【发布时间】:2018-04-22 17:36:46
【问题描述】:
我正在尝试在由片段组成的选项卡视图活动中显示AlertDialog。
这是我的java代码
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
switch (item.getItemId()) {
case R.id.dis:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); //Read Update
alertDialog.setTitle("Support us to improve");
alertDialog.setMessage(R.string.w4);
alertDialog.show();
alertDialog.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
return true;
default:
return super.onOptionsItemSelected(item);
}
}
现在我可以显示对话框了,但是 onclick 监听器对setPositiveButton() 不起作用,对话框中没有显示按钮。
这是我现在的输出,我如何在这里添加一个按钮。
【问题讨论】:
标签: android android-alertdialog