我正在尝试打开一个包含列表的警报对话框,供用户选择一些选项,但该对话框将从选项菜单项中打开。我已经包含了选项项目和对话框菜单的代码。
public void OnOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case SECTION:
showDialogMenu();
new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
showDialogMenu();
Log.d("Dialog used.","here");
}
}; break;
}
}
public void showDialogMenu(){
Log.d("showDialogMenu()", "Method was called.");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.dialogueTitle);
builder.setPositiveButton("Melee", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
num=0;
whichImage(num);
}
});
builder.setPositiveButton("Pistols", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
num=27;
whichImage(num);
}
});
builder.setPositiveButton("Shotguns", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
num=38;
whichImage(num);
}
});
builder.setPositiveButton("Rifles", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
num=43;
whichImage(num);
}
});
builder.setPositiveButton("Sub-Machine Guns", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
num=58;
whichImage(num);
}
});
builder.setPositiveButton("Light Machine Guns", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
num=68;
whichImage(num);
}
});
builder.setPositiveButton("Sniper Rifles", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item) {
num=72;
whichImage(num);
}
});
builder.show();
}
我确保有对话框的 show() 方法,我认为这是之前的问题,但是当单击菜单项时,什么也没有出现。任何帮助将不胜感激,谢谢。