public class SimpleOptionMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.icon: Toast.makeText(this, "You pressed the icon!", Toast.LENGTH_LONG).show();
break;
case R.id.text: Toast.makeText(this, "You pressed the text!", Toast.LENGTH_LONG).show();
break;
case R.id.icontext: Toast.makeText(this, "You pressed the icon and text!", Toast.LENGTH_LONG).show();
break;
}
return true;
}
}
res/menu/menu.xml ファイルを作成して入力しました。このクラスがアクティビティのみを拡張すると正常に動作しますが、ListActivity を使用するとクラッシュし続けます。リスト アクティビティを使用する別のアプリを使用しているときに、これに気付きました。[長く懸命に検索した後。:|]