1
彈出對話框是否有可能有打開一個對話框窗口的選項菜單項? 這裏就是我的了:安卓:打開自定義從選項菜單
public class main extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int score;
SharedPreferences stats = getSharedPreferences("TRHprefs", MODE_WORLD_READABLE);
score = stats.getInt("score", 0);
switch (item.getItemId()) {
case R.id.score:
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.options_menu);
dialog.setTitle("Hero Stats");
TextView b10 = (TextView) dialog.findViewById(R.id.tolevel);
b10.setText("Score: " + score);
dialog.setCancelable(true);
dialog.show();
break;
case R.id.options:
//Options
break;
case R.id.quit:
//Quit
break;
}
return true;
}
}
當我選擇了比分選項按鈕,該應用程序強制關閉。有任何想法嗎?
可否請您提供logcat的輸出,它只是猜測,沒有它。 – EpicOfChaos