这是我的代码:
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();
我的问题是点击拒绝时活动没有关闭。
任何人都可以帮助我吗?
答案 0 :(得分:1)
那是因为你已经切换了按钮的标签。
//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
}
});
答案 1 :(得分:0)
试试这个:
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();