@Override
public void onBackPressed() {
// TODO Auto-generated method stub
PopIt("Exit Application", "Are you sure you want to exit?");
super.onBackPressed();
}
public void PopIt( String title, String message ){
new AlertDialog.Builder(this)
.setTitle( title )
.setMessage( message )
.setPositiveButton("YES", new OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1) {
//do stuff onclick of YES
finish();
}
}).setNegativeButton("NO", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
//do stuff onclick of CANCEL
Toast.makeText(getBaseContext(), "You touched CANCEL", Toast.LENGTH_SHORT).show();
}
}).show();
}
此警报对话框速度太快,因为我无法阅读或点击它!为什么会这样?
答案 0 :(得分:5)
问题是你在调用super.onBackPressed()之前抛出Popit; 删除它:)
答案 1 :(得分:2)
super.onBackPressed();
删除此行。
如果您不删除它,将触发默认功能,这将关闭当前活动。
答案 2 :(得分:1)
试试这个
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
PopIt("Exit Application", "Are you sure you want to exit?");
}
答案 3 :(得分:1)
试试这个
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("Really Exit?")
.setMessage("Are you sure you want to exit?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
youractivity.super.onBackPressed();
}
}).create().show();
}
答案 4 :(得分:1)
删除此行super.onBackPressed();
您正在onBackPressed()
中显示对话框所以它就像你的onBackPressed();
的首要行为所以不要调用超类方法。
答案 5 :(得分:1)
删除super.onBackPressed();
这将有效:
public void onBackPressed() {
// TODO Auto-generated method stub
PopIt("Exit Application", "Are you sure you want to exit?");
}