Friday, January 28, 2011

Android Menu Creation

Android Menu Creation.
DOWNLOAD SOURCE CODE
If you click menu button it will be displaying menu in android.

source code:
MenuActivity:

public class ManuActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        ManuStructure menuStr = new ManuStructure();
        menuStr.createOptionsMenu(menu, ManuStructure.MENU1_PAGE);
    return super.onCreateOptionsMenu(menu);
    }   
}



MenuStructure:

public class ManuStructure {
    private static final int MENU1= Menu.FIRST;
    private static final int MENU2 = Menu.FIRST+1;
    private static final int MENU3 = Menu.FIRST+2;
   
    public static final int MENU1_PAGE = 1;
    public static final int MENU2_PAGE = 2;
    public static final int MENU3_PAGE = 3;
    public void createOptionsMenu(Menu menu, int fromPage )
    {       
        switch (fromPage) {
        case MENU1_PAGE :
            menu.add(0,MENU1 , 0,"MENU 1").setIcon(R.drawable.icon);
            menu.add(0, MENU2, 0,"MENU 2").setIcon(R.drawable.icon);
            menu.add(0, MENU3, 0,"MENU 3").setIcon(R.drawable.icon);
           
            break;
        }
    }
}

1 comment:

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...