Example usage for android.view MenuItem setVisible

List of usage examples for android.view MenuItem setVisible

Introduction

In this page you can find the example usage for android.view MenuItem setVisible.

Prototype

public MenuItem setVisible(boolean visible);

Source Link

Document

Sets the visibility of the menu item.

Usage

From source file:android.com.example.contactslist.ui.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from  w w  w.  j a va  2  s .  co m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent additional
    // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching, the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.forktech.cmerge.ui.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from  w ww.j  a va2s.  c  o m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent
    // additional
    // searches. In Android 3.0 and later, searching is done via a
    // SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching,
    // the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar
    // SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the
                // search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has
                // changed. Updates
                // the search filter, and restarts the loader to do
                // a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same
                // as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;
                mAdapter.setSearchTerm(newFilter);

                // Restarts the loader. This triggers
                // onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        // if (Utils.hasICS()) {
        // // This listener added in ICS
        // searchItem.setOnActionExpandListener(new
        // MenuItem.OnActionExpandListener() {
        // @Override
        // public boolean onMenuItemActionExpand(MenuItem menuItem) {
        // // Nothing to do when the action item is expanded
        // return true;
        // }
        //
        // @Override
        // public boolean onMenuItemActionCollapse(MenuItem menuItem) {
        // // When the user collapses the SearchView the current search
        // string is
        // // cleared and the loader restarted.
        // if (!TextUtils.isEmpty(mSearchTerm)) {
        // onSelectionCleared();
        // }
        // mSearchTerm = null;
        // mAdapter.setSearchTerm(null);
        // getLoaderManager().restartLoader(
        // ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
        // return true;
        // }
        // });
        // }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.hippo.nimingban.ui.ListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);

    mNMBClient = NMBApplication.getNMBClient(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    mSlidingDrawerLayout = (SlidingDrawerLayout) findViewById(R.id.drawer_layout);
    mContentLayout = (ContentLayout) mSlidingDrawerLayout.findViewById(R.id.content_layout);
    mRecyclerView = mContentLayout.getRecyclerView();
    mLeftDrawer = (LeftDrawer) mSlidingDrawerLayout.findViewById(R.id.left_drawer);
    mRightDrawer = (RightDrawer) mSlidingDrawerLayout.findViewById(R.id.right_drawer);

    final GestureDetector gestureDetector = new GestureDetector(this, new SimpleGestureListener());
    gestureDetector.setOnDoubleTapListener(new SimpleDoubleTapListener() {
        @Override/*from  www  .  j a  v a  2s.  c o  m*/
        public boolean onDoubleTap(MotionEvent e) {
            mPostHelper.refresh();
            return true;
        }
    });
    toolbar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            gestureDetector.onTouchEvent(event);
            return true;
        }
    });
    setSupportActionBar(toolbar);

    mDrawerToggle = new ActionBarDrawerToggle(this, mSlidingDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            if (mLeftDrawer == drawerView) {
                super.onDrawerSlide(drawerView, slideOffset);
            }
        }

        private void setMenuItemVisible(MenuItem item, boolean visible) {
            if (item != null) {
                item.setVisible(visible);
            }
        }

        @Override
        public void onDrawerClosed(View view) {
            if (mLeftDrawer == view) {
                super.onDrawerClosed(view);
            }
            if (mRightDrawer == view) {
                setMenuItemVisible(mRule, true);
                setMenuItemVisible(mCreatePost, true);
                setMenuItemVisible(mRefresh, true);
                setMenuItemVisible(mSortForumsMenu, false);
            }
        }

        @Override
        public void onDrawerOpened(View view) {
            if (mLeftDrawer == view) {
                // Analysis
                Analysis.action(ListActivity.this, "open_left_drawer");

                super.onDrawerOpened(view);
            }
            if (mRightDrawer == view) {
                // Analysis
                Analysis.action(ListActivity.this, "open_right_drawer");

                setMenuItemVisible(mRule, false);
                setMenuItemVisible(mCreatePost, false);
                setMenuItemVisible(mRefresh, false);
                setMenuItemVisible(mSortForumsMenu, true);
            }
        }
    };
    mSlidingDrawerLayout.setDrawerListener(mDrawerToggle);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
    }

    mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_left),
            Gravity.LEFT);
    mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_right),
            Gravity.RIGHT);
    mSlidingDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));

    mPostHelper = new PostHelper();
    mPostHelper.setEmptyString(getString(R.string.no_post));
    mContentLayout.setHelper(mPostHelper);
    if (Settings.getFastScroller()) {
        mContentLayout.showFastScroll();
    } else {
        mContentLayout.hideFastScroll();
    }

    mPostAdapter = new PostAdapter();
    mRecyclerView.setAdapter(mPostAdapter);
    mRecyclerView
            .setSelector(RippleSalon.generateRippleDrawable(ResourcesUtils.getAttrBoolean(this, R.attr.dark)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setOnItemClickListener(new ClickPostListener());
    mRecyclerView.hasFixedSize();
    mRecyclerView.setClipToPadding(false);

    int halfInterval = getResources().getDimensionPixelOffset(R.dimen.card_interval) / 2;
    if (getResources().getBoolean(R.bool.two_way)) {
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        mRecyclerView.addItemDecoration(new MarginItemDecoration(halfInterval));
        mRecyclerView.setPadding(halfInterval, halfInterval, halfInterval, halfInterval);
        mRecyclerView.setItemAnimator(new FloatItemAnimator(mRecyclerView));
    } else {
        mRecyclerView.addItemDecoration(new MarginItemDecoration(0, halfInterval, 0, halfInterval));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setPadding(0, halfInterval, 0, halfInterval);
    }

    mLeftDrawer.setHelper(this);

    mRightDrawer.setRightDrawerHelper(this);

    if (savedInstanceState == null) {
        int ils = Settings.getImageLoadingStrategy();
        if (ils == Settings.IMAGE_LOADING_STRATEGY_ALL || (ils == Settings.IMAGE_LOADING_STRATEGY_WIFI
                && NMBApplication.isConnectedWifi(ListActivity.this))) {
            mLeftDrawer.loadHeaderImageView();
        }
    }

    updateForums(true);

    checkForAppStart();

    Messenger.getInstance().register(Constants.MESSENGER_ID_CREATE_POST, this);
    Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this);

    // Check permission
    PermissionRequester.request(this, Manifest.permission.WRITE_EXTERNAL_STORAGE,
            getString(R.string.write_storage_permission_tip), PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);

    if (Settings.getGuideListActivity()) {
        showLeftDrawerGuide();
    }
}

From source file:com.www.avtovokzal.org.MainActivity.java

private void loadSystemInfo() {
    String url = "http://www.avtovokzal.org/php/app/system_1.3.5_v1.php";

    if (isOnline()) {
        StringRequest strReq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override//from w  ww .j  a v  a2 s  . c o m
            public void onResponse(String response) {
                String md5hashFromSettings;
                String md5hashEkbFromSettings;

                if (response == null) {
                    callErrorActivity();
                    finish();
                }

                JSONObject dataJsonQbj;

                if (Constants.LOG_ON)
                    Log.v("Result", response);

                try {
                    dataJsonQbj = new JSONObject(response);
                    JSONArray system = dataJsonQbj.getJSONArray("system");

                    JSONObject oneObject = system.getJSONObject(0);

                    dateNow = oneObject.getString("date");
                    update = oneObject.getBoolean("update");
                    String md5hash = oneObject.getString("md5");
                    String md5hashEkb = oneObject.getString("md5_ekb");

                    //  ?? ?
                    if (!update && toolbarMenu != null) {
                        MenuItem item = toolbarMenu.findItem(R.id.lamp);
                        item.setVisible(true);
                    }

                    // ?  
                    textView = (TextView) findViewById(R.id.header);
                    String string = getString(R.string.main_schedule) + " " + dateNow;
                    textView.setText(string);
                    SharedPreferences.Editor editorDate = settings.edit();
                    editorDate.putString(Constants.APP_PREFERENCES_DATE, dateNow);
                    editorDate.apply();

                    //  ??  ? ?? ?
                    md5hashFromSettings = settings.getString(Constants.APP_PREFERENCES_MD5, "");
                    md5hashEkbFromSettings = settings.getString(Constants.APP_PREFERENCES_MD5_EKB, "");

                    if (Constants.LOG_ON) {
                        Log.v("MD5 from Settings Ekb",
                                md5hashEkbFromSettings + " " + md5hashEkb.equals(md5hashEkbFromSettings));
                        Log.v("MD5 Ekb", md5hashEkb);
                        Log.v("MD5 from Settings",
                                md5hashFromSettings + " " + md5hash.equals(md5hashFromSettings));
                        Log.v("MD5", md5hash);
                    }

                    // ?   md5 ? ?  ?
                    if (!md5hash.equals(md5hashFromSettings)) {
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putBoolean(Constants.APP_PREFERENCES_MD5_CHECK, false);
                        editor.putString(Constants.APP_PREFERENCES_MD5, md5hash);
                        editor.apply();
                        if (Constants.LOG_ON)
                            Log.v("Settings", "Station false");
                    }
                    if (!md5hashEkb.equals(md5hashEkbFromSettings)) {
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putBoolean(Constants.APP_PREFERENCES_MD5_EKB_CHECK, false);
                        editor.putString(Constants.APP_PREFERENCES_MD5_EKB, md5hashEkb);
                        editor.apply();
                        if (Constants.LOG_ON)
                            Log.v("Settings", "Station_ekb false");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (Constants.LOG_ON)
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                callErrorActivity();
            }
        });
        // ? TimeOut, Retry
        strReq.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 3,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        // ? ?  
        AppController.getInstance().addToRequestQueue(strReq);
    } else {
        callErrorActivity();
    }
}

From source file:com.evandroid.musica.fragment.LyricsViewFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.lyrics, menu);
    MenuItem saveMenuItem = menu.findItem(R.id.save_action);
    if (saveMenuItem != null) {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
        if (mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT
                && sharedPref.getBoolean("pref_auto_save", true)) {
            String[] metadata = new String[] { mLyrics.getArtist(), mLyrics.getTrack(),
                    mLyrics.getOriginalArtist(), mLyrics.getOriginalTrack() };
            if (!DatabaseHelper.presenceCheck(((MainLyricActivity) getActivity()).database, metadata)) {
                lyricsPresentInDB = true;
                new WriteToDatabaseTask().execute(this, saveMenuItem, mLyrics);
            }//  w  ww  .  java  2s .  co m
            saveMenuItem.setVisible(false);
        } else {
            saveMenuItem.setIcon(lyricsPresentInDB ? R.drawable.ic_trash : R.drawable.ic_save);
            saveMenuItem.setTitle(lyricsPresentInDB ? R.string.remove_action : R.string.save_action);
        }
    }
    MenuItem resyncMenuItem = menu.findItem(R.id.resync_action);
    MenuItem convertMenuItem = menu.findItem(R.id.convert_action);
    if (mLyrics != null) {
        resyncMenuItem.setVisible(mLyrics.isLRC());
        convertMenuItem.setVisible(mLyrics.isLRC());
    }
}

From source file:com.nononsenseapps.notepad.ActivityMain.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.setGroupVisible(R.id.activity_menu_group, isDrawerClosed);
    menu.setGroupVisible(R.id.activity_reverse_menu_group, !isDrawerClosed);

    final MenuItem donateItem = menu.findItem(R.id.menu_donate);
    if (donateItem != null) {
        donateItem.setVisible(!mDonatedInApp);
    }/*from www .  j av  a  2 s. c om*/

    return super.onPrepareOptionsMenu(menu);
}

From source file:org.andstatus.app.TimelineActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    mOptionsMenu = menu;/*w w  w . j av  a 2  s  .co  m*/
    MyAccount ma = MyContextHolder.get().persistentAccounts().getCurrentAccount();
    boolean enableReload = isTimelineCombined() || ma.isValidAndVerified();
    MenuItem item = menu.findItem(R.id.reload_menu_item);
    item.setEnabled(enableReload);
    item.setVisible(enableReload);

    prepareDrawer();

    if (mContextMenu != null) {
        mContextMenu.setAccountUserIdToActAs(0);
    }

    if (mMessageEditor != null) {
        mMessageEditor.onPrepareOptionsMenu(menu);
    }

    boolean enableGlobalSearch = MyContextHolder.get().persistentAccounts().isGlobalSearchSupported(ma,
            isTimelineCombined());
    item = menu.findItem(R.id.global_search_menu_id);
    item.setEnabled(enableGlobalSearch);
    item.setVisible(enableGlobalSearch);

    return super.onPrepareOptionsMenu(menu);
}

From source file:br.com.mybaby.contatos.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//from  ww w. j  a  v  a 2  s.co  m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contatos_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent additional
    // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching, the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Util.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Util.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Util.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.android.contacts.activities.PeopleActivity.java

private void makeMenuItemVisible(Menu menu, int itemId, boolean visible) {
    final MenuItem item = menu.findItem(itemId);
    if (item != null) {
        item.setVisible(visible);
    }//from w  w w  . j  a  v  a2 s  .  c om
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

private void updateButtons() {
    MenuItem resendAction = actionMode.getMenu().findItem(R.id.resend_button);
    MenuItem copyAction = actionMode.getMenu().findItem(R.id.copy_button);
    MenuItem shareAction = actionMode.getMenu().findItem(R.id.share_button);
    MenuItem infoAction = actionMode.getMenu().findItem(R.id.info_button);

    int count = adapter.getCheckedItemCount();

    boolean resendVisible = false;
    if (count == 1) {
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                if (!adapter.getItem(i).isDelivered() && !adapter.getItem(i).isDeliveryInProgress()) {
                    resendVisible = true;
                    break;
                }//from   ww w  .j a v  a2s  .  co  m
            }
        }
    }
    resendAction.setVisible(resendVisible);

    if (count >= 2) {
        infoAction.setVisible(false);
        copyAction.setVisible(false);
        shareAction.setVisible(false);
    } else {
        infoAction.setVisible(true);
        copyAction.setVisible(true);
        shareAction.setVisible(true);
    }
}