在我的Android应用程序中,我显示了警告对话框。当我点击OnBack按钮时,警报对话框被取消了。我的问题是用户点击那个onBack buton。我必须显示该对话框。我们可以处理这个问题。提前谢谢。
AlertDialog.Builder alertbox = new AlertDialog.Builder( HomeScreenActivity.this);
alertbox.setMessage("Please select a Favorite Business");
alertbox.setNeutralButton("Nearby", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1) { } })
.setNegativeButton("Search",new DialogInterface.OnClickListener()
{ public void onClick(DialogInterface dialog,int id) { } });
alertbox.show();
答案 0 :(得分:1)
答案 1 :(得分:1)
试试这个
public void onBackPressed() {
AlertDialog.Builder alertbox = new AlertDialog.Builder( HomeScreenActivity.this);
alertbox.setMessage(""Please select a Favorite Business")
.setCancelable(false)
.setNuetralButton("Nearby", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Search", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
alertbox.create();
alertbox.show();
}
};
答案 2 :(得分:1)
你需要这样的东西:
dialog.setOnKeyListener(new OnKeyListener(){
@Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_BACK){
return true;
}
return false;
}});