我在我的应用程序中实现了BaseActivity模式,除了尝试显示警报对话框外,一切都很好。这就是发生的事情
当我尝试取消对话框时,我就离开了。
这里是显示位于基本活动中的对话框的代码:
new AlertDialog.Builder(this)
.setTitle("Logging out")
.setMessage("Are you sure?")
.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UIUtils.setAnimation(swipeRefreshLayout, true);
UserBaas.logoutUser();
}
})
.setNegativeButton("No", null)
.show();
此问题在模拟器和实际设备上是持久的。可能是什么问题?
switch (item) {
case NAVDRAWER_ITEM_HOME:
startActivity(new Intent(this, MainActivity.class));
break;
case NAVDRAWER_ITEM_MEMOS:
intent = new Intent(this, MemoGroupActivity.class);
intent.putExtra("section", MemoGroupActivity.MEMO);
createBackStack(intent);
break;
case NAVDRAWER_ITEM_GROUPS:
intent = new Intent(this, MemoGroupActivity.class);
intent.putExtra("section", MemoGroupActivity.GROUP);
createBackStack(intent);
break;
case NAVDRAWER_ITEM_CONNECTIONS:
createBackStack(new Intent(this, ConnectionsActivity.class));
break;
case NAVDRAWER_ITEM_DOCUMENTS:
createBackStack(new Intent(this, DocumentsActivity.class));
break;
case NAVDRAWER_ITEM_SETTINGS:
createBackStack(new Intent(this, SettingsActivity.class));
break;
case NAVDRAWER_ITEM_LOGOUT:
showLogoutDialog();
break;
}
继承了UIUtils.setAnimation()
的代码public static void setAnimation(SwipeRefreshLayout swipeRefreshLayout, boolean value) {
swipeRefreshLayout.setEnabled(value);
swipeRefreshLayout.setRefreshing(value);
}
答案 0 :(得分:0)
我认为参数Context,你可以改变这个==> Activity.this(Activity是要显示对话框的Activity类的名称)
答案 1 :(得分:0)
试试这个:
.setNegativeButton(Cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
});
答案 2 :(得分:0)
试试这个:
AlertDialog.Builder b = new AlertDialog.Builder(Your_Activity_Name.this);
b.setTitle("Logging out");
b.setMessage("Are you sure?");
b.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do something
}
});
b.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
b.create().show();
答案 3 :(得分:0)
试试这样。:
.setNegativeButton(Cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
});