我正在寫食譜書,而且我遇到了一個問題 - 當我點擊我的菜單項時,應該發送電子郵件,電子郵件地址和主題預填充,沒有任何反應......當我點擊我的「發送電子郵件」菜單項時,爲什麼沒有發生?
任何想法爲什麼?
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;
}
}
的事情是,菜單項項和菜單項recipe_suggest是兩個不同的菜單? – Bercik
item是onOptionsItemSelected *方法的接收方式,item的對象類型是MenuItem,item保存關於被按下的內容的基本信息,無論是home按鈕還是菜單中的任何項目,理論上仍然應該調用此方法由框架。 – FabianCook
recipe_suggest是一個項目,它是您需要引用的「ID」,recipe_suggest是XML文件的一部分是否正確?這是recipe_menu1中的一個項目是否正確? ID爲recipe_suggest是否正確?當您構建項目時,ID將被「存儲」在R文件中,並具有附加在它上面的「引用」int,其名稱recipe_suggest位於類R中的子類ID中,R類是您引用的內容然後引用包含值recipe_suggest的類id,它保存的int與附加到調用的菜單項的int匹配。 :D對不起 – FabianCook