Example usage for android.view Menu findItem

List of usage examples for android.view Menu findItem

Introduction

In this page you can find the example usage for android.view Menu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadListFragment.java

/**
 * Initialize's the ThreadList's menu./*from w w  w .  j av  a 2s . c o  m*/
 * 
 * @param menu
 *            The Menu of the fragment.
 * @param inflater
 *            A MenuInflater to inflate the fragment's menu.
 */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.thread_list, menu);
    MenuItem item = menu.findItem(R.id.action_settings);
    item.setVisible(true);
}

From source file:fr.bde_eseo.eseomega.plans.PlansActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    // Retrieve the SearchView and plug it into SearchManager
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//  w  ww  .  j a  v  a2s  .co m
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {

            if (newText.length() > 0) {
                searchInArray(newText);
                addHeaders();
            } else {
                fillItems();
                addHeaders();
            }
            mAdapter.notifyDataSetChanged();
            if (roomItemsDisplay.size() > 0)
                recList.scrollToPosition(0);
            return true;
        }
    });
    return true;
}

From source file:net.dian1.player.activity.HomeActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (Dian1Application.getInstance().getPlayerEngineInterface() == null
            || Dian1Application.getInstance().getPlayerEngineInterface().getPlaylist() == null) {
        menu.findItem(R.id.player_menu_item).setVisible(false);
    } else {/*from  w w w .  j  a v  a2 s .c om*/
        menu.findItem(R.id.player_menu_item).setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:br.com.bioscada.apps.biotracks.fragments.MarkerDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.marker_detail, menu);

    updateWaypoint(false);/*from  w  w w .j  a v  a 2s.c  o  m*/

    Track track = myTracksProviderUtils.getTrack(waypoint.getTrackId());
    boolean isSharedWithMe = track != null ? track.isSharedWithMe() : true;

    menu.findItem(R.id.marker_detail_edit).setVisible(!isSharedWithMe);
    menu.findItem(R.id.marker_detail_delete).setVisible(!isSharedWithMe);

    String photoUrl = waypoint.getPhotoUrl();
    boolean hasPhoto = photoUrl != null && !photoUrl.equals("");
    menu.findItem(R.id.marker_detail_view_photo).setVisible(hasPhoto);

    TrackIconUtils.setMenuIconColor(menu);
}

From source file:at.bitfire.davdroid.mirakel.syncadapter.LoginURLFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean ok = editUserName.getText().length() > 0 && editPassword.getText().length() > 0;

    if (ok)//from  w  ww .j  a  v  a 2  s  .c o m
        // check host name
        try {
            URI uri = new URI(URLUtils.sanitize(scheme + editBaseURI.getText().toString()));
            if (StringUtils.isBlank(uri.getHost()))
                ok = false;
        } catch (URISyntaxException e) {
            ok = false;
        }

    MenuItem item = menu.findItem(R.id.next);
    item.setEnabled(ok);
}

From source file:com.dnielfe.manager.Browser.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.getMenuInflater().inflate(R.menu.main, menu);

    mMenuItemPaste = menu.findItem(R.id.paste);
    mMenuItemPaste.setVisible(!ClipBoard.isEmpty());
    return true;/*from  www  . j a v a2s.c  o m*/
}

From source file:com.example.android.touroflondon.MainActivity.java

/**
 * Create the option menu. Compiled from the common menu description (common.xml).
 * In addition, when in the phone layout, the phone.xml menu description is also appended.
 *
 * @param menu//ww  w .j av  a  2 s  . c om
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.common, menu);

    // Load special action items for the phone layout.
    if (!mIsTablet) {
        inflater.inflate(R.menu.phone, menu);
        if (mPoiListFragment != null && mPoiListFragment.isVisible()) {
            mPoiMenuItem = menu.findItem(R.id.menu_poi);
            mPoiMenuItem.setVisible(false); //hide by default
        }
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.sharemenu, menu);
    // set options menu view
    upvote = menu.findItem(R.id.menu_upvote);
    downvote = menu.findItem(R.id.menu_downvote);

    if (userLikes.equals("true")) {
        upvote.setIcon(R.drawable.upvote_active);
        curvote = 1;/* w  w  w . j  av  a 2s. co m*/
    } else if (userLikes.equals("false")) {
        downvote.setIcon(R.drawable.downvote_active);
        curvote = -1;
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:blackman.matt.boardlist.BoardListActivity.java

/**
 * When the option menu is created this handles the creation events.
 *
 * @param menu The menu being created.//  w w w.j  ava  2 s  . co  m
 * @return If the creation was a success.
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_board_list, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search_list);
    mSearchView = new MySearchView(this);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setOnCloseListener(this);
    mSearchView.setIconified(true);
    //mSearchView.setBackground(R.color.post_background_color);
    searchItem.setActionView(mSearchView);
    return true;
}

From source file:com.adrguides.ReadGuideFragment.java

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.read_guide, menu);

    menu.findItem(R.id.action_playpause).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//from  w w  w  .j  a v a  2 s  . c o m
        public boolean onMenuItemClick(MenuItem menuItem) {
            ttsfragment.playstartpause();
            return true;
        }
    });

    menu.findItem(R.id.action_next).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            ttsfragment.gotoNext();
            return true;
        }
    });

    menu.findItem(R.id.action_previous).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            ttsfragment.gotoPrevious();
            return true;
        }
    });
    menu.findItem(R.id.action_list).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            new ListDialogFragment().show(getFragmentManager(), ListDialogFragment.TAG);
            return true;
        }
    });

    menu.findItem(R.id.action_viewguide).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {

            //                Intent internetIntent = new Intent(Intent.ACTION_VIEW);
            //                internetIntent.setData(Uri.parse(ttsfragment.getGuide().getAddress()));
            //                startActivity(internetIntent);

            Intent intent = new Intent(getActivity(), WebViewActivity.class);
            intent.putExtra(WebViewActivity.EXTRA_URL, ttsfragment.getGuide().getAddress());
            intent.putExtra(WebViewActivity.EXTRA_TITLE, ttsfragment.getGuide().getTitle());
            startActivity(intent);

            return true;
        }
    });

    menu.findItem(R.id.action_bookmark).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            new SaveGuideTask(ReadGuideFragment.this.getActivity().getApplicationContext())
                    .execute(ttsfragment.getGuide());
            return true;
        }
    });

    searchview = new SearchViewGuides(getActivity(), menu.findItem(R.id.menu_search));
}