这是我的代码,我正在创建一个对话框,要求用户在取消时将应用程序发送到后台。我收到了这个错误:
11-26 14:12:01.197:E / ViewRootImpl(5472):sendUserActionEvent()mView == null
mbtnimglogout.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
closeapp();
}});
}
void closeapp()
{
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Closing Dealer Form")
.setMessage("Are you sure you want to send Application to Background?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
moveTaskToBack(true);
// finish();
}
})
.setNegativeButton("No", null)
.show();
}
答案 0 :(得分:0)
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}}).show();
答案 1 :(得分:0)
您必须设置取消选项的监听器:
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
供参考,请参阅本教程Here