Android Menu - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Menu class.

This code example shows how to use the following methods:setHeaderTitle, add
    } 
 
    @Override 
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle("Context menu");
        menu.add("List item 1");
        menu.add("List item 2");
        menu.add("List item 3");
    } 
 
    private static class SimpleListAdapter extends ArrayAdapter<String> {
        public SimpleListAdapter(Context context) {
            super(context, android.R.layout.simple_list_item_1, DATA_LIST);
        } 
 
        @Override 
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView v = (TextView) super.getView(position, convertView, parent);
            final Resources r = getContext().getResources();
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add
 
    // Demonstrate how to add your own menus to app 
 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        int base = Menu.FIRST;
        // Group, item id, order, title 
        menu.add(base, base, base, "Item1");
        menu.add(base, base + 1, base + 1, "Item2");
        menu.add(base, base + 2, base + 2, "Item3");
        return true; 
    } 
 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
        LOG.d("menus", "Item " + item.getItemId() + " pressed.");
        this.appView.loadUrl("javascript:alert('Menu " + item.getItemId() + " pressed.')");
        return super.onOptionsItemSelected(item);
    } 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add
    private static final int ERASE_MENU_ID = Menu.FIRST + 3;
    private static final int SRCATOP_MENU_ID = Menu.FIRST + 4;
 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
 
        menu.add(0, COLOR_MENU_ID, 0, "Color").setShortcut('3', 'c');
        menu.add(0, EMBOSS_MENU_ID, 0, "Emboss").setShortcut('4', 's');
        menu.add(0, BLUR_MENU_ID, 0, "Blur").setShortcut('5', 'z');
        menu.add(0, ERASE_MENU_ID, 0, "Erase").setShortcut('5', 'z');
        menu.add(0, SRCATOP_MENU_ID, 0, "SrcATop").setShortcut('5', 'z');
 
        /****   Is this the mechanism to extend with filter effects? 
        Intent intent = new Intent(null, getIntent().getData()); 
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE); 
        menu.addIntentOptions( 
                              Menu.ALTERNATIVE, 0, 
                              new ComponentName(this, NotesList.class), 
                              null, intent, 0, null); 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add
    } 
 
    /** Called when the menubar is being created by Android. */ 
    public boolean onCreateOptionsMenu(Menu menu) {
        Log.i(TAG, "onCreateOptionsMenu");
        mMenuSketch = menu.add("Sketch or Painting");
        mMenuAlien = menu.add("Alien or Human");
        mMenuEvil = menu.add("Evil or Good");
        mMenuDebug = menu.add("[Debug mode]");
        return true; 
    } 
 
    /** Called whenever the user pressed a menu item in the menubar. */ 
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.i(TAG, "Menu Item selected: " + item);
        if (item == mMenuSketch)
            mView.toggleSketchMode();
        else if (item == mMenuAlien)
            mView.toggleAlienMode();
        else if (item == mMenuEvil)
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:findItem
        return true; 
    } 
 
    @Override 
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        boolean hasSelection = (getSelectedItemPosition() >= 0);
 
        menu.findItem(MENU_ADD).setVisible(true);
        menu.findItem(MENU_EDIT).setVisible(hasSelection);
        menu.findItem(MENU_DELETE).setVisible(hasSelection);
 
        return true; 
    } 
 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:  // See ActionBar#setDisplayHomeAsUpEnabled()
                Intent intent = new Intent(this, FdnSetting.class);
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add
	 
	 
	@Override 
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		menu.add("Remove");
		menu.add("Configure");
	} 
 
	@Override 
	public boolean onContextItemSelected(android.view.MenuItem item) {
		AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
		int position = info.position;
		 
		if(item.getTitle().equals("Remove")) {
			OrgAgenda.removeAgenda(position, getActivity());
			refresh(); 
			return true; 
		} else if(item.getTitle().equals("Configure")) {
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add, addSubMenu, clear
	} 
 
	@Override 
    public boolean onPrepareOptionsMenu(Menu menu) 
    { 
	    menu.clear();
	 
	    if(chkMenuExtendido.isChecked()) 
	    	construirMenu(menu, true);
	    else  
	    	construirMenu(menu, false);
	 
	    return super.onPrepareOptionsMenu(menu);
    } 
	 
	private void construirMenu(Menu menu, boolean extendido)
    { 
		//1) Método 1: Inflar menu XML 
		//getMenuInflater().inflate(R.menu.activity_main, menu); 
		 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add
 
    // Demonstrate how to add your own menus to app 
 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        int base = Menu.FIRST;
        // Group, item id, order, title 
        menu.add(base, base, base, "Item1");
        menu.add(base, base + 1, base + 1, "Item2");
        menu.add(base, base + 2, base + 2, "Item3");
        return true; 
    } 
 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
        LOG.d("menus", "Item " + item.getItemId() + " pressed.");
        this.appView.loadUrl("javascript:alert('Menu " + item.getItemId() + " pressed.')");
        return super.onOptionsItemSelected(item);
    } 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add, removeItem
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        MenuItem item;
         
            // first, get rid of our menus (if any) 
        menu.removeItem(0);
        menu.removeItem(1);
         
            // next, add back item(s) based on current menu mode 
        switch (mMenuMode.getSelectedItemPosition())
        { 
        case MENUMODE_SEARCH_KEY:
            item = menu.add( 0, 0, 0, "(Search Key)");
            break; 
             
        case MENUMODE_MENU_ITEM:
            item = menu.add( 0, 0, 0, "Search");
            item.setAlphabeticShortcut(SearchManager.MENU_KEY);
            break; 
             

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setHeaderTitle, add
        /** 
         * {@inheritDoc} 
         */ 
        public void onCreateContextMenu(ContextMenu menu, View v,
                ContextMenuInfo menuInfo) {
            menu.setHeaderTitle("Theme");
            menu.add(1, 1, 1, "JFree");
            menu.add(1, 2, 2, "Darkness");
            menu.add(1, 3, 3, "Legacy");
        } 
         
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public boolean onContextItemSelected(MenuItem aItem) {
        if (aItem.getItemId() == 1) {
            ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme()); 
            applyThemeToChart(); 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android Menu Questions & Answers:

Other Android Menu Examples

17:	
18:	  @Override
19:	  public boolean onCreateOptionsMenu(Menu menu) {
20:	    // Inflate the menu; this adds items to the action bar if it is present.
21:	    getMenuInflater().inflate(R.menu.activity_main, menu);

Read More

33:	
34:	  @Override
35:	  public boolean onCreateOptionsMenu(Menu menu) {
36:	    MenuInflater inflater = getMenuInflater();
37:	    inflater.inflate(R.menu.mainmenu, menu);

Read More

40:	
41:	  @Override
42:	  public boolean onCreateOptionsMenu(Menu menu) {
43:	    getMenuInflater().inflate(R.menu.activity_main, menu);
44:	    return true;

Read More

7:	
8:		@Override
9:		public boolean onCreateOptionsMenu(Menu menu) {
10:			MenuInflater inflater = getMenuInflater();
11:			inflater.inflate(R.menu.activity_main_actions, menu);

Read More

16:	    // Initiating Menu XML file (menu.xml)
17:	    @Override
18:	    public boolean onCreateOptionsMenu(Menu menu)
19:	    {
20:	        MenuInflater menuInflater = getMenuInflater();

Read More

1:		public boolean onCreateOptionsMenu(Menu menu) {
2:			MenuInflater inflater = getMenuInflater();
3:			inflater.inflate(R.menu.activity_main_actions, menu);

Read More

1:	@Override
2:	public boolean onCreateOptionsMenu(Menu menu) {
3:	    MenuInflater inflater = ;
4:	    inflater.inflate(R.menu.game_menu, menu);

Read More

1:	@Override
2:	public boolean onCreateOptionsMenu(Menu menu){
3:	    super.onCreateOptionsMenu(menu);
4:

Read More

24:	
25:	    @Override
26:	    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
27:	        // Inflate the menu for the CAB
28:	        MenuInflater inflater = mode.getMenuInflater();
-
38:	
39:	    @Override
40:	    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
41:	        // Here you can perform updates to the CAB due to
42:	        // an  request

Read More

See Code Examples for Android Menu Methods: