Search This Blog

Thursday, March 8, 2012

Creating the Options Menu and Itemselected methods in android

You can use the following code inside the menu.xml

<?xml version="1.0" encoding="utf-8"?>
android:title="menu1 title"
android:title="menu2 title"

now the two methods for the invoking the menu and function which is to be called on the item selected.

public boolean onCreateOptionsMenu (Menu menu){
//menu.add(Menu.NONE, 101,Menu.FIRST,this.getResources().getString(R.string.Title));
MenuInflater mi = getMenuInflater();
mi.inflate(, menu);
return true;

you can use the both the method of invoking the menu. First one by the menu.add and second one by the inflating the menu.xml file Now on the itemselectedlistner is used by the following code.

public boolean onOptionsItemSelected(MenuItem item){
                       // your code here
                       // your code here
     return false;

just pass the id in switch-case and do whatever you want by selecting the those menu.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.