2011-05-24 29 views
1
//called when hardware button "Menu" clicked 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.menu, menu); 
     return true; 
    } 

,然后这个机器人表演对话不起作用

@Override 
    public boolean onMenuItemSelected(int featureId, MenuItem item) { 
     switch (item.getItemId()) { 
     case R.id.menu_options: 
       startActivity(new Intent(this, EditPreferences.class)); 
       break; 
     case R.id.menu_about: 
      Dialog dialog = new Dialog(getApplicationContext()); 
       dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//NO TITLE :) 
       dialog.setContentView(R.layout.menu_about); 
       dialog.setCancelable(true); 
       dialog.show(); 
      break; 

     default: 
      break; 
     } 

//return true; 
//return false; 
     return super.onMenuItemSelected(featureId, item); 
    } 

使用调试我看到我进入开关的情况下R.id.menu_about,但dialog.show()什么都不做

对话框就不会显示,我尝试使用非标准AlertDialog也没有运气或者

+0

你得到一个错误?如果是这样请张贴。 – AedonEtLIRA 2011-05-24 16:24:54

+0

没有错误,只是消失的菜单栏 – max4ever 2011-05-24 16:25:53

回答

8

尝试改变:

Dialog dialog = new Dialog(getApplicationContext()); 

Dialog dialog = new Dialog(this); 
+1

Omg,我刚刚看到。我无法相信我错过了它。 @Max,是对话框(一般视图)不能使用应用程序上下文创建。 – AedonEtLIRA 2011-05-24 16:39:41

+1

谢谢,我一直认为getApplicationContext()和这是一样的东西,这两者之间有什么不同? :) – max4ever 2011-05-25 07:53:50

+1

它用于保持全局应用程序:http://developer.android.com/reference/android/app/Application.html – pawelzieba 2011-05-25 14:12:02