Android MenuItem - 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 MenuItem class.

This code example shows how to use the following methods:getItemId
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
    	// This passes the menu option string to OF 
    	// you can add additional behavior from java modifying this method 
    	// but keep the call to OFAndroid so OF is notified of menu events 
    	if(OFAndroid.menuItemSelected(item.getItemId())){
    		 
    		return true; 
    	} 
    	return super.onOptionsItemSelected(item);
    } 
     
 
    @Override 
    public boolean onPrepareOptionsMenu (Menu menu){
    	// This method is called every time the menu is opened 
    	//  you can add or remove menu options from here 
    	return  super.onPrepareOptionsMenu(menu);
    } 
	 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemId, getMenuInfo
        .setIcon(R.drawable.delete).setAlphabeticShortcut('d');
  } 
 
  @Override 
  public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case DELETE_ID:
        AdapterView.AdapterContextMenuInfo info=
            (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
 
        delete(info.id);
        return(true); 
    } 
 
    return(super.onOptionsItemSelected(item));
  } 
 
  public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    return(new CursorLoader(this, Provider.Constants.CONTENT_URI,
                            PROJECTION, null, null, null));
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemId
        return true; 
    } 
 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true; 
            case MENU_OVERFLOW:
                mMenuDrawer.toggleMenu();
                return true; 
        } 
        return super.onOptionsItemSelected(item);
    } 
 
    /** 
     * Click handler for top drawer items. 
     */ 
    @Override 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemId
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
    	// This passes the menu option string to OF 
    	// you can add additional behavior from java modifying this method 
    	// but keep the call to OFAndroid so OF is notified of menu events 
    	if(OFAndroid.menuItemSelected(item.getItemId())){
    		 
    		return true; 
    	} 
    	return super.onOptionsItemSelected(item);
    } 
     
 
    @Override 
    public boolean onPrepareOptionsMenu (Menu menu){
    	// This method is called every time the menu is opened 
    	//  you can add or remove menu options from here 
    	return  super.onPrepareOptionsMenu(menu);
    } 
	 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemId, getMenuInfo
        .setAlphabeticShortcut('d'); 
  } 
 
  @Override 
  public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case DELETE_ID:
        AdapterView.AdapterContextMenuInfo info=
          (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
 
        delete(info.id);
        return(true); 
    } 
 
    return(super.onOptionsItemSelected(item));
  } 
 
  public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    return(new CursorLoader(this, Provider.Constants.CONTENT_URI,
                            PROJECTION, null, null, null));
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemId
     * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) 
     */ 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
 
        if (super.onOptionsItemSelected(item) == true) {
            return true; 
        } 
 
        switch (item.getItemId()) {
            case android.R.id.home:
                finish(); 
                return true; 
 
            default: 
                return false; 
        } 
    } 
 
    /* 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setIntent, setShowAsAction, setVisible
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
 
            // Set the intent to the help menu item, show the help menu item in the overflow 
            // menu, and make it visible. 
            helpMenuItem.setIntent(intent);
            helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            helpMenuItem.setVisible(true);
 
            // return that the help menu item is visible (i.e., true) 
            return true; 
        } 
    } 
 
    /** 
     * Adds two query parameters into the Uri, namely the language code and the version code 
     * of the app's package as gotten via the context. 
     * @return the uri with added query parameters 
     */ 
    private static Uri uriWithAddedParameters(Context context, Uri baseUri) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemId
        Toast.makeText(this, "Clicked: " + str, Toast.LENGTH_SHORT).show();
    } 
 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                mMenuDrawer.toggleMenu();
                return true; 
        } 
 
        return super.onOptionsItemSelected(item);
    } 
 
    @Override 
    public void onBackPressed() { 
        final int drawerState = mMenuDrawer.getDrawerState();
        if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
            mMenuDrawer.closeMenu();
            return; 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemId
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
    	// This passes the menu option string to OF 
    	// you can add additional behavior from java modifying this method 
    	// but keep the call to OFAndroid so OF is notified of menu events 
    	if(OFAndroid.menuItemSelected(item.getItemId())){
    		 
    		return true; 
    	} 
    	return super.onOptionsItemSelected(item);
    } 
     
 
    @Override 
    public boolean onPrepareOptionsMenu (Menu menu){
    	// This method is called every time the menu is opened 
    	//  you can add or remove menu options from here 
    	return  super.onPrepareOptionsMenu(menu);
    } 
	 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setActionView, setIcon, setShowAsAction
    } 
 
    @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // Place an action bar item for searching. 
        MenuItem item = menu.add("Search");
        item.setIcon(android.R.drawable.ic_menu_search);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
                | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
        SearchView sv = new SearchView(getActivity());
        sv.setOnQueryTextListener(this);
        item.setActionView(sv);
    } 
 
    public boolean onQueryTextChange(String newText) {
        // Called when the action bar search text has changed.  Update 
        // the search filter, and restart the loader to do a new query 
        // with this filter. 
        mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
        getLoaderManager().restartLoader(0, null, this);
        return true; 
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android MenuItem Questions & Answers:

Other Android MenuItem Examples

40:	
41:	  @Override
42:	  public boolean onOptionsItemSelected(MenuItem item) {
43:	    Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
44:	    return true;

Read More

6:		 * */
7:		@Override
8:		public boolean onOptionsItemSelected(MenuItem item) {
9:			// Take appropriate action for each action item click
10:			switch (item.getItemId()) {

Read More

28:	     * */
29:	    @Override
30:	    public boolean onOptionsItemSelected(MenuItem item)
31:	    {
32:

Read More

24:	
25:		// Refresh menu item
26:		private MenuItem refreshMenuItem;
27:	
28:		@Override
-
43:		 * */
44:		@Override
45:		public boolean onOptionsItemSelected(MenuItem item) {
46:			// Take appropriate action for each action item click
47:			switch (item.getItemId()) {

Read More

1:	@Override
2:	public boolean onOptionsItemSelected(MenuItem item) {
3:	    switch (item.getItemId()) {
4:	        case R.id.vibrate:

Read More

1:	@Override
2:	public boolean onOptionsItemSelected(MenuItem item) {
3:	    // Handle item selection
4:	    switch (item.getItemId()) {

Read More

1:	@Override
2:	public boolean onContextItemSelected(MenuItem item) {
3:	    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
4:	    switch (item.getItemId()) {

Read More

See Code Examples for Android MenuItem Methods: