由于在项目中会经常用到dialog和toast

在这里对这两个做了一个封装。

方便后面直接调用。

public class AlertUtil {

private static Context mContext;

public static void showToast(Context context,String text){

mContext = context;

Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();

}

public static void showAlertDialog(final Context mContext,String text){

new AlertDialog.Builder(mContext)

.setTitle("提示")

.setMessage(text)

.setPositiveButton("确定", new OnClickListener(){


@Override

public void onClick(DialogInterface arg0, int arg1) {

// TODO Auto-generated method stub

showToast(mContext, "choose ok");

}

})

.create()

.show();

}

}

//调用方法如下

1、AlertUtil.showToast(this, "show toast");

2、AlertUtil.showAlertDialog(this, "show dialog");