這是我用過的菜單項選擇代碼:Android的菜單CustomDailog - 應用forcecloses本身
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
showDialog(1);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
有菜單隻有一個選項,我設計了一個customDialog使用下面的代碼:
protected Dialog onCreateDialog(int id) {
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("About Us");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("App Created By: Prateek Garg ([email protected])");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.logo_resumes);
return dialog;
}
}
問題是,只要我按菜單項「關於我們」,應用程序強行關閉自己。 我無法糾正任何錯誤,但我希望你們可以。
在此先感謝。 PS。我在onCreateOptionsMenu()中創建了menuInflator()。
乾杯
logcat中顯示了以下錯誤:[我DONOT知道該怎麼理解或刪除它們... :(]
07-27 23:35:04.569:W/dalvikvm( 648):線程ID = 1:螺紋與未捕獲的異常(組離開= 0x40a13300)
07-27 23:35:04.659:E/AndroidRuntime(648):致命異常:主
07-27 23: 35:04.659:E/AndroidRuntime(648):android.view.WindowMa nager $ BadTokenException:無法添加窗口 - 令牌null不適用於應用程序
07-27 23:35:04.659:E/AndroidRuntime(648):at android.view.ViewRootImpl.setView(ViewRootImpl.java: 589)
07-27 23:35:04.659:E/AndroidRuntime(648):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326) 和lott more。
如果你們說的話,我會包括其他的錯誤太多,但我認爲他們只是因爲第1或2的形成就是這種情況一般
Logcat中顯示的錯誤是什麼? – Aerrow 2012-07-27 17:44:08
請再次發佈您在LogCat中看到的錯誤 – 2012-07-27 17:53:33
如果您需要尋求LogCat幫助,請告訴我們。該錯誤將顯示爲紅色。在錯誤消息中查找您的軟件包名稱併發布整個事情。 – 2012-07-27 17:54:11