2
所以我有这个代码。我想要做的是当我按下带ID帮助的按钮时(案例R.id.help)我想要一个自定义文本出现在对话框中。此代码似乎工作,除了出现对话框,然后立即消失......有什么问题?Android:对话框立即消失
下面的代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.icon:
Intent intent = new Intent(this, Main.class);
startActivity(intent);
case R.id.help:
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage("This is the alertbox!");
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
}
});
// show it
alertbox.show();
}
return true;
}
}
没有什么变化。 :/ – Simonas
你没有在你的开关/外壳中使用任何中断。 alertbox.show()之后是否有任何代码? ? – xevincent
不,就是这样.. – Simonas