我想使用菜單充氣器給用戶的電子郵件尋求支持的選項,但每次我點擊菜單按鈕上的模擬器它什麼都不會做。這是我的代碼。謝謝!!!菜單inflater沒有運行在模擬器上
我需要在我的清單中編輯這個嗎?我的XML具有菜單的標題和項以及項目
,這裏是我的xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/email" android:title="@string/email_menu"
android:icon="@drawable/ic_envelope" android:onClick="emailme" />
<item android:id="@+id/test1" android:title="@string/test1"
android:icon="@drawable/ic_dashboard" android:onClick="test1" />
</menu>
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MenuButton extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.menu.menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.email:
emailme();
return true;
case R.id.test1:
test1();
return false;
default:
return super.onOptionsItemSelected(item);
}
}
private void test1() {
// TODO Auto-generated method stub
}
private void emailme() {
// TODO Auto-generated method stub
String domsEmail = "[email protected]";
String message = "Hello, I just want to let you know that your app";
String myemail[] = { domsEmail };
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, myemail);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "your app");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(emailIntent);
}
}
你也可以發佈你的menu.xml的xml代碼..可以幫忙。 – Urban
首先粘貼你的menu.xml。 –
更新了它。並把它放在第一個 – domshyra