2011-07-07 9 views
4

簡単な質問です。私は、オプションメニューのボタンを押すと、ポップアップするだけのテキストを持つ静的ダイアログメッセージが必要です。これは私のメニューコードです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: 
       //popup window code here 
     } 
     return true; 
    } 
} 

私はそれを最も簡単な方法ですか?ありがとう!

答えて

4
@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: 
      //popup window code here 
Toast.makeText(this, "This is the Toast message", Toast.LENGTH_LONG).show(); 

    } 
    return true; 
} 
} 

でまたはu iは、ダイアログボックスを使用することができます

@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: 
      //popup window code here 
AlertDialog.Builder alertbox = new AlertDialog.Builder(this); 

     // set the message to display 
     alertbox.setMessage("This is the alertbox!"); 

     // add a neutral button to the alert box and assign a click listener 
     alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() { 

      // click listener on the alert box 
      public void onClick(DialogInterface arg0, int arg1) { 
       // the button was clicked 

      } 
     }); 

     // show it 
     alertbox.show(); 

    } 
    return true; 
} 

}

+0

2番目のオプションが動作しているようですが、ダイアログボックスがポップアップしますが、それ以降はMain.classアクティビティに戻ります。どうしたの? :) – Simonas

+0

私は知らない... – kannappan

+0

くそー...手掛かりはありませんか?コードはかなり簡単に見えます。 :/ – Simonas

0

あなたが作成できる簡単なダイアログ

static final int DIALOG_MESSAGE_ID= 0; 

protected Dialog onCreateDialog(int id) { 
    switch(id) { 
    case DIALOG_MESSAGE_ID: 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setMessage("Your message ")//your message 
     }); 
    return builder.create(); 
    break; 
    } 
    return null; 
} 


//in your code 
case R.id.help: 
    showDialog(DIALOG_MESSAGE_ID); 

よりhttp://developer.android.com/guide/topics/ui/dialogs.html

0
AlertDialog.Builder dialog = new AlertDialog.Builder(context); 
dialog.setMessage("Blah Blah..."); 
dialog.show(); 
関連する問題