Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. Create a new menu xml file in the res/menu folder.
  2. Add an item to the menu with the attribute android:id="@+id/textviewmenu_item" and android:title="TextView".
  3. In the Main Activity's onCreateOptionsMenu() method, inflate the menu xml file and return true.
  4. In the Main Activity's onOptionsItemSelected() method, check if the selected menu item is the textviewmenu_item.
  5. If it is, create a new TextView element using the findViewById() method with the id R.id.text_view, and set its text to "Hello World".
  6. Finally, add the TextView element to the Main Activity's layout using the addView() method of the parent container.