[英]How to close Activity after clicking Progress Dialog Button
那是我的代码:
LayoutInflater inflater= LayoutInflater.from(this);
View view=inflater.inflate(R.layout.dialog, null);
alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Titel");
alertDialog.setView(view);
alertDialog.setNegativeButton(getString(R.string.accept), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Activity.this.finish();
}
});
alertDialog.setPositiveButton(getString(R.string.decline), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// handle accepting
}
});
alert = alertDialog.create();
alert.show();
我的问题是单击“拒绝”时“活动”没有关闭。
谁能帮我?
那是因为您已经切换了按钮的标签。
//was R.string.accept
alertDialog.setNegativeButton(getString(R.string.decline), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Activity.this.finish();
}
});
//was R.string.decline
alertDialog.setPositiveButton(getString(R.string.accept), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// handle accepting
}
});
尝试这个:
alertDialog.setNegativeButton(getString(R.string.accept), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
alertDialog.setPositiveButton(getString(R.string.decline), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Activity.this.finish();
}
});
alert = alertDialog.create();
alert.show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.