package app.test; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class Test extends Activity { public static final int ITEM0 = Menu.FIRST; public static final int ITEM1 = Menu.FIRST + 1; Button button1; Button button2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button1.setVisibility(View.INVISIBLE); button2.setVisibility(View.INVISIBLE); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, ITEM0, 0, "button1"); menu.add(0, ITEM1, 0, "button2"); menu.findItem(ITEM1); return true; } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case ITEM0: actionClickMenuItem1(); break; case ITEM1: actionClickMenuItem2(); break; } return super.onOptionsItemSelected(item);} private void actionClickMenuItem1(){ setTitle("button1"); button1.setVisibility(View.VISIBLE); button2.setVisibility(View.INVISIBLE); } private void actionClickMenuItem2(){ setTitle("button2"); button1.setVisibility(View.INVISIBLE); button2.setVisibility(View.VISIBLE); } } //main.xml android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:layout_height="wrap_content" android:text="@string/hello" /> android:layout_width="100px" android:layout_height="wrap_content" android:text="@string/button1" /> android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button2" /> //strings.xml Hello World, ActivityMenu HelloMenu button1 button2