我的应用程序中有一个对话框,当单击对话框中的按钮时,将显示一个上下文菜单。但我的问题是 onContextItemSelected 没有被调用。我的代码正在对话框外的其他按钮中工作。
这是我的代码:
dialog = new Dialog(SuperPizzaActivity.this, R.style.DialogSlideAnim);
dialog.setTitle("Select Size and Crust");
dialog.setContentView(R.layout.pizzadialog);
final Button select = (Button) dialog.findViewById(R.id.superpizzadselect);
select.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
menu.setHeaderTitle("Choose One");
menu.add(1, 1, 1, "Add Chicken");
menu.add(2, 2, 2, "Add Pasta");
menu.add(3, 3, 3, "Add Drinks");
menu.add(4, 4, 4, "Continue");
}
});
select.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
openContextMenu(v);
}
});
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
switch (item.getItemId()) {
case 1:
dialog.dismiss();
Intent i1 = new Intent(SuperPizzaActivity.this,SuperChickenActivity.class);
i1.putExtra(checker, checker);
startActivity(i1);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
break;
case 2:
dialog.dismiss();
Intent i = new Intent(SuperPizzaActivity.this,SuperPastaActivity.class);
i.putExtra(checker, checker);
startActivity(i);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
break;
case 3:
dialog.dismiss();
Intent i2 = new Intent(SuperPizzaActivity.this,SuperDrinksActivity.class);
i2.putExtra(checker, checker);
startActivity(i2);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
break;
case 4:
dialog.dismiss();
Intent i3 = new Intent(SuperPizzaActivity.this,SuperSummaryList.class);
startActivity(i3);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
break;
}
return true;
}
任何想法将不胜感激。