1、先写一个Dialog类
CustomDialog
package com.example.heng.adtest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.widget.Toast;
public class CustomDialog {
//声明一个Diaglog
private AlertDialog.Builder builder;
//上下文对象
private Context context;
public CustomDialog(Context cnt)
{
this.context = cnt;
}
//声明弹出框方法
//buttontext :按钮名称
//title :标题
//message:信息
//callbock:返回信息
public void CreateDialog(String buttontext, String title, String message, final CallBack callbock){
builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
//添加确定按钮
builder.setPositiveButton(buttontext, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//业务逻辑判断
callbock.isConfirm(true);
}
});
builder.create().show();
}
public interface CallBack{
public void isConfirm(boolean flag);
}
//声明toasts方法 比较简单的提示框。
public void createToasts(String message) {
Toast.makeText(context,message,Toast.LENGTH_LONG).show();
}
}