List of usage examples for android.view Menu findItem
public MenuItem findItem(int id);
From source file:es.uniovi.imovil.fcrtrainer.BaseExerciseFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.game_control, menu); MenuItem item = menu.findItem(R.id.action_change_game_mode); try {//from w ww. j a v a 2 s . c o m MainActivity activity = (MainActivity) getActivity(); if (item != null && activity != null) { item.setVisible(!activity.isDrawerOpen()); } } catch (ClassCastException ex) { // El fragmento est incrustado en una actividad distinta a // MainActivity. No se hace nada } MenuItem setup = menu.findItem(R.id.action_settings); if (mIsPlaying) { item.setIcon(R.drawable.ic_action_stop); setup.setVisible(false); } else { item.setIcon(R.drawable.ic_action_play); setup.setVisible(true); } }
From source file:ca.appvelopers.mcgillmobile.ui.MapActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.search, menu); // Get the SearchView MenuItem item = menu.findItem(R.id.action_search); Assert.assertNotNull(getSupportActionBar()); final SearchView searchView = new SearchView(this); final int textViewID = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);//from w ww.ja va2 s . c o m final AutoCompleteTextView searchTextView = (AutoCompleteTextView) searchView.findViewById(textViewID); try { // Set the cursor to the same color as the text Field cursorDrawable = TextView.class.getDeclaredField("mCursorDrawableRes"); cursorDrawable.setAccessible(true); cursorDrawable.set(searchTextView, 0); } catch (Exception e) { Timber.e(e, "Cannot change color of cursor"); } // Set up the query listener MenuItemCompat.setActionView(item, searchView); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { searchString = query; filterBySearchString(); return false; } @Override public boolean onQueryTextChange(String newText) { searchString = newText; filterBySearchString(); return false; } }); //Reset the search view searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { searchString = ""; filterBySearchString(); return false; } }); return true; }
From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { Log.v(TAG, "onCreateOptionsMenu: mMeeting =" + mMeeting); inflater.inflate(R.menu.meeting_menu, menu); // Only share and show charts for finished meetings final MenuItem shareItem = menu.findItem(R.id.action_share_meeting); if (shareItem != null) shareItem.setVisible(mMeeting != null && mMeeting.getState() == State.FINISHED); final MenuItem chartItem = menu.findItem(R.id.action_charts_meeting); if (chartItem != null) chartItem.setVisible(mMeeting != null && mMeeting.getState() == State.FINISHED); // Delete a meeting in any state. final MenuItem deleteItem = menu.findItem(R.id.action_delete_meeting); if (deleteItem != null) deleteItem.setVisible(mMeeting != null); }
From source file:com.teleca.jamendo.activity.HomeActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (JamendoApplication.getInstance().getPlayerEngineInterface() == null || JamendoApplication.getInstance().getPlayerEngineInterface().getPlaylist() == null) { menu.findItem(R.id.player_menu_item).setVisible(false); } else {/* ww w. j av a 2 s . co m*/ menu.findItem(R.id.player_menu_item).setVisible(true); } return super.onPrepareOptionsMenu(menu); }
From source file:com.openerp.addons.note.EditNoteFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_fragment_note_detail, menu); // disabling the MORE [:] menu MenuItem item_operation = menu.findItem(R.id.menu_note_operation); item_operation.setVisible(false);/*w ww . java 2 s . c o m*/ }
From source file:com.akhbulatov.wordkeeper.ui.fragment.WordListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragment_word, menu); MenuItem searchItem = menu.findItem(R.id.menu_search_word); SearchView searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(//from ww w . jav a 2s .c om searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class))); searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { final Cursor cursor = mWordDbAdapter.getAll(sSortMode); final int column = cursor.getColumnIndex(WordEntry.COLUMN_NAME); if (newText.length() > 0) { mWordAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column)); mTextEmptyWordList.setVisibility(View.GONE); if (mWordAdapter.getItemCount() == 0) { String escapedNewText = TextUtils.htmlEncode(newText); String formattedNoResults = String.format(getString(R.string.no_results_word), escapedNewText); CharSequence styledNoResults = Html.fromHtml(formattedNoResults); mTextNoResultsWord.setText(styledNoResults); mTextNoResultsWord.setVisibility(View.VISIBLE); } else { mTextNoResultsWord.setVisibility(View.GONE); } } else { mWordAdapter.swapCursor(cursor); mTextNoResultsWord.setVisibility(View.GONE); if (mWordAdapter.getItemCount() == 0) { mTextEmptyWordList.setVisibility(View.VISIBLE); } } return true; } }); }
From source file:at.bitfire.davdroid.mirakel.syncadapter.EnterCredentialsFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { boolean ok = editUserName.getText().length() > 0 && editPassword.getText().length() > 0; if (ok) {//from w w w .j a v a 2s . com // check host name try { URI uri = new URI(URIUtils.sanitize(protocol + editBaseURL.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.zigvine.zagriculture.UIPreferenceActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); menu.findItem(R.id.menu_logoff).setVisible(MainApp.isSignIn()); menu.findItem(R.id.menu_settings).setVisible(false); return true;//from ww w.j a v a2 s .com }
From source file:net.kourlas.voipms_sms.activities.ConversationsActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.conversations, menu); this.menu = menu; SearchView searchView = (SearchView) menu.findItem(R.id.search_button).getActionView(); searchView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*from w w w. jav a 2 s .c o m*/ public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { adapter.refresh(newText); return true; } }); return super.onCreateOptionsMenu(menu); }
From source file:com.slp.rss_api.activity.EditFeedActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (mTabHost.getCurrentTab() == 0) { menu.findItem(R.id.menu_add_filter).setVisible(false); } else {// w ww . ja v a2s .c o m menu.findItem(R.id.menu_add_filter).setVisible(true); } return super.onPrepareOptionsMenu(menu); }