如何让搜索按钮从关闭一个AlertDialog? [英] How to keep search button from closing an AlertDialog?
本文介绍了如何让搜索按钮从关闭一个AlertDialog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我创建一个独立的alertdialog与建筑商(未连接到活动/视图)我怎能搜索按钮从导致alertdialog关闭?
If I create a standalone alertdialog with the builder (not connected to the activity/view) how can I keep the search button from causing the alertdialog to close?
感谢。
推荐答案
我也面临同样的问题,同时显示最终用户许可协议对话框。 它是由setOnKeyListener解决。
I'm also faced the same problem while showing EULA Dialog. It was solved by setOnKeyListener.
下面是解决方案:
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
.setTitle(title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.EULA_VERSION, versionInfo.versionCode);
editor.commit();
dialogInterface.dismiss();
}
})
.setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Close the activity once the EULA is declined.
mActivity.finish();
}
});
//To avoid skipping EULA screen through search & menu button.
builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode < KeyEvent.KEYCODE_DPAD_UP || keyCode > KeyEvent.KEYCODE_DPAD_CENTER)
{
return true;
}
else
return false;
}
});
builder.create().show();
这篇关于如何让搜索按钮从关闭一个AlertDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文