【发布时间】:2011-09-30 09:14:37
【问题描述】:
所以我有这个代码。我想要做的是当我按下带有 ID 帮助的按钮(案例 R.id.help)时,我希望自定义文本出现在对话框中。这段代码似乎可以工作,只是对话框出现然后立即消失......有什么问题?
代码如下:
@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;
}
}
【问题讨论】: