2012-05-04 9 views
0

私はレシピブックを書いていますが、問題が発生しました。電子メールを送信する予定のメニュー項目をクリックすると、電子メールアドレスと件名が事前に入力されているため、何も起こりません...「メール送信」メニュー項目をクリックしても何も起こりません。

任意のアイデアなぜ???

public class recipedisplayscreen extends Activity { 

TextView EmailAddress; 

TextView EmailSubject; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.recipedisplayscreen); 

     TextView MethodDisplay = (TextView) findViewById(R.id.textView3); 
     TextView IngredientsDisplay = (TextView) findViewById(R.id.textView5); 


     Intent i = getIntent(); 
     String Ingredients = i.getStringExtra("textView1"); 
     String Method = i.getStringExtra("textView2"); 
     Log.e("recipedisplayscreen", Ingredients + "." + Method); 

     MethodDisplay.setText(Method); 
     IngredientsDisplay.setText(Ingredients); 

     EmailAddress=(TextView) findViewById(R.id.textView2); 
     EmailSubject=(TextView) findViewById(R.id.textView4); 


     ActionBar actionBar = getActionBar(); 
     setTitle(R.string.title); 
     actionBar.setDisplayHomeAsUpEnabled(true); 
     setTitle(Method);} 

     @Override 
     public boolean onOptionsItemSelected(MenuItem item) { 
      switch (item.getItemId()) { 
       case android.R.id.home: 
        // App icon in action bar clicked; go home 
        Intent intent = new Intent(this, MainScreen.class); 
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        startActivity(intent); 
        return true; 
       default: 
        return super.onOptionsItemSelected(item); 
      } 
     } 

     public boolean onOptionsItemSelected1(MenuItem recipe_suggest) { 
      final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      emailIntent.setType("plain/text"); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ EmailAddress.getText().toString()}); 
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EmailSubject.getText()); 

      startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
      return true; 
     } 




    @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
      MenuInflater inflater = getMenuInflater(); 
      inflater.inflate(R.menu.recipe_menu1, menu); 
      return true;   
    }  
} 

答えて

4

私は、これはあなたが望むものであると信じて:onOptionsItemSelected1を削除し、はこれでをonOptionsItemSelected置き換えるD、これはそのrecipe_suggestがメニュー項目のidであると仮定していますか?何スイッチ

@Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case android.R.id.home: 
       // App icon in action bar clicked; go home 
       Intent intent = new Intent(this, MainScreen.class); 
       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       startActivity(intent); 
       return true; 
      case R.id.recipe_suggest: 
       //Other menu item I believe 
       final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
       emailIntent.setType("plain/text"); 
       emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{     EmailAddress.getText().toString()}); 
       emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EmailSubject.getText()); 

       startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
       return true; 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 

はケースに「スイッチ」でオブジェクトを一致させる、「スイッチ」と一致する場合が行われますので、メニューアイテムid(MenuItemのアイテムであれば、item.getItemId( ))はIDであるandroid.R.id.homeまたはR.id.recipe_suggestと一致します(Android Rファイルを参照しているようにアクションバーを使用しているとします)。これは、私のknowlegde :)

+0

事はMenuItemの項目とメニュー項目recipe_suggestが2つの異なるメニューであるということですか? – Bercik

+0

アイテムは、* onOptionsItemSelected *メソッドが受け取るメソッドで、アイテムのオブジェクトタイプはMenuItemであり、アイテムは押されたものに関する基本情報を保持し、ホームボタンであってもメニュー内のアイテムであっても、フレームワークによって。 – FabianCook

+0

recipe_suggestはアイテムです。参照する必要のある「ID」、recipe_suggestはXMLファイルの一部です。 recipe_menu1の項目は正しいですか? ID recipe_suggestが正しい?プロジェクトをビルドするとき、IDはRファイルに格納され、クラスR内のサブクラスID内にrecipe_suggestという名前でそのクラスに「参照」intが付いています。クラスRは参照するものです次に、値recipe_suggestを保持するクラスidを参照します。保持するintは、呼び出しに関連付けられたメニュー項目のintと一致します。 Dは申し訳ありません – FabianCook

0

あなたは2つのonOptionsItemSelectedを持っているので?まあ、onOptionsItemSelected * *と呼ばれ、実際のものにマージする必要があります。

0

onOptionsItemSelected1()というメソッドを作成するだけで、アンドロイドがメニューエントリを押してメールを送信したときにアンドロイドがそれを呼び出すとは限りません。

このメソッドを元のonOptionsItemSelected()にマージし、動作させるよりも正しいケースに入れてください。

0

なぜ、あなたはonOptionsItemSelectedという別のメソッドを持っていますか? *?アクション項目に反応すべてのコードがにする必要があります

をonOptionsItemSelected:

public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case android.R.id.home: 
      // App icon in action bar clicked; go home 
      Intent intent = new Intent(this, MainScreen.class); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(intent); 
      return true; 

     case android.R.id.email_action_item: 

      final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      (...) 
     default: 
      return super.onOptionsItemSelected(item); 
    } 
} 
関連する問題