【发布时间】:2017-12-01 13:36:18
【问题描述】:
单击后退按钮时,警报对话框消失。不给我选择的机会。假设当 m == null || 时会弹出此对话框m.getPosition() == null。 “m”是变量“Marker m”
@Override
public void onBackPressed() {
HabitEventController hec = new HabitEventController(this);
if(m != null && m.getPosition() != null){
hec.setHabitEventLocation(heID, m.getPosition());
}
if(m == null || m.getPosition() == null){
new AlertDialog.Builder(this)
.setTitle("Really Exit?")
.setMessage("Are you sure you want to exit, without creating a marker?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
MapsActivity.super.onBackPressed();
}
}).show();
}
//Remove this call because your app will close and crash before display the dialog
// finish();
}
【问题讨论】:
-
什么是 m??????
-
我的错。 “标记 m”
-
你知道
m有什么价值吗??并且该检查是有道理的,您的m不等于null,因此它跳过了其中的代码。 -
代码有效。我的问题是对话框消失得很快。
-
尝试
setcancelable(false)获取警报对话框
标签: android android-studio-3.0