一个优雅AlertDialogUtil工具类

11 篇文章 0 订阅

为了节省代码的复用性,小小的进行封装,易上手,操作简单。

package com.main.utils;

import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;

import com.chuxin.lmq.R;
import com.main.HbApplication;
import com.main.view.MainActivity;

/**
 * @创建者 CSDN_苗小源
 * @描述  对话框工具类
 */

public class AlertDialogUtil {

    private static AlertDialogUtil mAlertDialogUtil;
    public static AlertDialog.Builder builder;

    public void showAlertDialog( @Nullable int setMessage, int setNegativeButton, int setPositiveButton, DialogInterface.OnClickListener DialogInterface1, DialogInterface.OnClickListener   DialogInterface2){

        builder.setMessage(setMessage);
        builder.setNegativeButton(setNegativeButton, DialogInterface1);
        builder.setPositiveButton(setPositiveButton,DialogInterface2 );
        builder.show();
    }

    public static AlertDialogUtil getInstance(Context mContent){
        if (mAlertDialogUtil==null){
            synchronized(AlertDialogUtil.class){
                if (mAlertDialogUtil==null)
                    mAlertDialogUtil=new AlertDialogUtil();
                     builder = new AlertDialog.Builder(mContent, R.style.Theme_AppCompat_Light_Dialog_Alert);
            }
        }
        return mAlertDialogUtil;
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,Java线程池是Java提供的一种线程管理机制,通过线程池可以更好地管理系统中的线程。下面我来介绍一下如何编写一个Java线程池工具类。 1. 创建一个ThreadPoolExecutor对象,用于管理线程池。 2. 定义一个任务类,该类实现Runnable接口,并重写run()方法,run()方法中实现具体的任务逻辑。 3. 在工具类中,定义一个execute()方法,用于向线程池提交任务,该方法接收一个Runnable对象作为参数,将该任务提交到线程池中。 4. 定义一个shutdown()方法,用于关闭线程池,该方法调用ThreadPoolExecutor的shutdown()方法即可。 5. 定义一个getActiveCount()方法,用于获取当前活跃的线程数,该方法调用ThreadPoolExecutor的getActiveCount()方法即可。 6. 可以根据需要定义其他方法,如getPoolSize()、getCorePoolSize()等。 下面是一个简单的Java线程池工具类示例: ``` import java.util.concurrent.*; public class ThreadPoolUtil { private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor( 5, // 核心线程数 10, // 最大线程数 60, // 线程空闲时间 TimeUnit.SECONDS, // 线程空闲时间单位 new LinkedBlockingQueue<>(), // 线程池任务队列 Executors.defaultThreadFactory(), // 线程工厂 new ThreadPoolExecutor.AbortPolicy() // 拒绝策略 ); public static void execute(Runnable task) { threadPool.execute(task); } public static void shutdown() { threadPool.shutdown(); } public static int getActiveCount() { return threadPool.getActiveCount(); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值