AndroidAlertDialog对话框回调
封装的Dialog对话框,有时候需要获取选项这时候就用到了函数的回调
创新互联建站成立与2013年,先为西青等服务建站,西青等地企业,进行企业商务咨询服务。为西青企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
package com.example.testlistq; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.view.KeyEvent; public class MyDialog { private static AlertDialog dialog; //回调接口 public interface ResultCallBack{ public void callback(boolean flag); } public static void showDialog(Context context, String str, final ResultCallBack mRCallBack){ dialog = new AlertDialog.Builder(context) .setTitle("提示") .setMessage(str) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(mRCallBack != null){ mRCallBack.callback(true); } } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(mRCallBack != null){ mRCallBack.callback(false); } } }).create(); dialog.setCancelable(false); dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH) {//屏蔽搜索键 return true; } else { return false; //默认返回 false } } }); dialog.show(); } }
//调用实例
MyDialog.showDialog(this, "回调窗口", new ResultCallBack() { @Override public void callback(boolean flag) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "flag = " + flag, Toast.LENGTH_SHORT).show(); } });
本文题目:AndroidAlertDialog对话框回调
网站路径:http://azwzsj.com/article/gsgghd.html