Skip to content

Instantly share code, notes, and snippets.

@sakurabird
Created October 24, 2011 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakurabird/1309022 to your computer and use it in GitHub Desktop.
Save sakurabird/1309022 to your computer and use it in GitHub Desktop.
Untouchable メニュー
//inflaterを使ってxmlリソースファイルを読み込んでメニューを作成する。
@Override
publicboolean onCreateOptionsMenu( Menu menu ) {
super.onCreateOptionsMenu( menu );
MenuInflater inflater = getMenuInflater();
//インフレートしています
inflater.inflate( R.menu.option_menu, menu );
returntrue;
}
//メニューで何か選択された場合の処理
@Override
publicboolean onOptionsItemSelected( MenuItem item ) {
super.onOptionsItemSelected( item );
// 通常メッセージをセットしておく
tv_sensor_message.setText( R.string.message_waiting );
//リソースのIDを使って、どのメニューが選択されたかを判定している。
switch ( item.getItemId() ) {
case R.id.menu_setting:
Intent settingIntent = new Intent( this, SettingActivity.class );
startActivity( settingIntent );
break;
case R.id.menu_help:
Intent intent = new Intent( mContext, HelpActivity.class );
intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity( intent );
break;
case R.id.menu_about:
showAboutDialog();
break;
case R.id.menu_sensor_sensitivity:
Intent sensorIntent = new Intent( mContext, SensorSensitivityActivity.class );
sensorIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity( sensorIntent );
break;
}
return super.onOptionsItemSelected( item );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment