如何在按下设备上的后退按钮时完成列表活动
我使用以下代码来完成活动,但我想在后按事件上完成列表活动。帮我 提前致谢
public void onBackPressed() {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setMessage("Want to exit ?");
alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
for(Activity activity:activities)
activity.finish();
} });
alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}});
alertDialog.show();
}
i m using the following code to finish an activity but i want to finish the list activity on back press event . help me
Thanks in advance
public void onBackPressed() {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setMessage("Want to exit ?");
alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
for(Activity activity:activities)
activity.finish();
} });
alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}});
alertDialog.show();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不会修改您的代码,只是在这里建议新代码,
I am not modifying the your code,just i am suggesting new code here,
您的代码应如下修改。
Your Code should be modified like below..
将取消侦听器添加到警报对话框中,然后从其中关闭您的活动。
Add a cancel listener to your alert dialog, and close your activity from within there.