在由片段组成的选项卡视图 activity 内显示 AlertDialog
displaying AlertDialog inside tab view activity consisting of fragments
我正在尝试在包含片段的选项卡视图 activity 中显示 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()
不起作用,按钮没有显示在对话框中。
这是我现在的输出,我如何在此处添加按钮。
在显示对话框之前添加肯定按钮。
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Support us to improve");
alertDialog.setMessage(R.string.w4);
alertDialog.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// Do your stuff
}
});
alertDialog.show();
另外你不需要调用 dialogInterface.dismiss();
它会自动关闭。默认按钮 AlertDialog's
属性。
我正在尝试在包含片段的选项卡视图 activity 中显示 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()
不起作用,按钮没有显示在对话框中。
这是我现在的输出,我如何在此处添加按钮。
在显示对话框之前添加肯定按钮。
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Support us to improve");
alertDialog.setMessage(R.string.w4);
alertDialog.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// Do your stuff
}
});
alertDialog.show();
另外你不需要调用 dialogInterface.dismiss();
它会自动关闭。默认按钮 AlertDialog's
属性。