List of usage examples for android.view Menu getItem
public MenuItem getItem(int index);
From source file:org.dmfs.webcal.NavbarActivity.java
protected void setupNavbar() { mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // this is a hack to get a Menu Menu menu = new PopupMenu(this, null).getMenu(); getMenuInflater().inflate(R.menu.side_navigation, menu); // remove invisible menu items int itemCount = menu.size(); int i = 0;/*from w w w . j av a 2 s . c o m*/ while (i < itemCount) { MenuItem item = menu.getItem(i); if (!item.isVisible()) { menu.removeItem(item.getItemId()); --itemCount; } else { ++i; } } MenuAdapter menuAdapter = new MenuAdapter(this, R.layout.navdrawer_item, android.R.id.title, menu); mDrawerList.setAdapter(menuAdapter); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { String activityTitle = getActivityTitle(); setTitle(activityTitle); invalidateOptionsMenu(); super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { setTitle(R.string.app_name); invalidateOptionsMenu(); super.onDrawerOpened(drawerView); } }; mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerList.setOnItemClickListener(this); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); }
From source file:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem menuItem_Star = menu.add(0, MENU_ITEM_STAR, menu.size(), R.string.description_star); MenuItemCompat.setShowAsAction(menuItem_Star, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); if (mIsStarred) { menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on); menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, checked"); } else {//from w ww . j a v a 2 s . com menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star); menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, not checked"); } MenuItem menuItem_Refresh = menu.add(1, MENU_ITEM_REFRESH, menu.size(), R.string.description_refresh); MenuItemCompat.setShowAsAction(menuItem_Refresh, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); menu.getItem(MENU_ITEM_REFRESH).setIcon(R.drawable.ic_menu_refresh); if (mRefreshState) { startRefreshAnimation(); } return super.onCreateOptionsMenu(menu); }
From source file:pt.ubi.di.pdm.swipe.CollectionDemoActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { menu.getItem(0).setVisible(false); return true; }
From source file:com.heske.alexandria.activities.MainActivity.java
private int findNavPosition() { Menu menu = mNavView.getMenu(); int count = menu.size(); for (int i = 0; i < count; i++) { if (menu.getItem(i).isChecked()) return i; }/*from www. j a va 2 s .c om*/ //Default to BookList return 0; }
From source file:com.eugene.fithealthmaingit.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) { mNavItemId = savedInstanceState.getInt(NAV_ITEM_ID); isFirstFragmentAdded = savedInstanceState.getBoolean(FIRST_FRAGMENT_ADDED); } else {// ww w. ja va2s . c o m mNavItemId = R.id.nav_journal; } mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); // Set menu header text to User Name TextView mHeaderText = (TextView) findViewById(R.id.txtName); mHeaderText.setText(PreferenceManager.getDefaultSharedPreferences(this).getString(Globals.USER_NAME, "")); /** * Initiate NavigationView * Inflate Menu based on FitBit connection status */ NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav); if (PreferenceManager.getDefaultSharedPreferences(this).getString("FITBIT_ACCESS_TOKEN", "").equals("")) { mNavigationView.inflateMenu(R.menu.drawer); } else { mNavigationView.inflateMenu(R.menu.drawer_fitbit); } mNavigationView.getMenu().findItem(mNavItemId).setChecked(true); mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() != R.id.nav_settings) { mNavItemId = menuItem.getItemId(); switchFragment(menuItem.getItemId()); menuItem.setChecked(true); Fragment loading = new FragmentBlankLoading(); Bundle b = new Bundle(); b.putInt(NAV_ITEM_ID, mNavItemId); loading.setArguments(b); getSupportFragmentManager().beginTransaction().replace(R.id.container, loading).commit(); } else { startActivity(new Intent(MainActivity.this, UserInformationActivity.class)); } handleNavigationDrawer(); return false; } }); // Nav Menu Fonts Menu m = mNavigationView.getMenu(); for (int i = 0; i < m.size(); i++) { MenuItem mi = m.getItem(i); //for aapplying a font to subMenu ... SubMenu subMenu = mi.getSubMenu(); if (subMenu != null && subMenu.size() > 0) { for (int j = 0; j < subMenu.size(); j++) { MenuItem subMenuItem = subMenu.getItem(j); applyFontToMenuItem(subMenuItem); } } //the method we have create in activity applyFontToMenuItem(mi); } switchFragment(mNavItemId); /** * Handles Home Screen Widget * Search and Add */ Intent widgetIntent = this.getIntent(); if (widgetIntent != null) { if (widgetIntent.getAction() != null && savedInstanceState == null) { if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_SEARCH)) { // Post delay to allow the app to open and not interfere with animation final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().beginTransaction() .replace(R.id.containerSearch, new FragmentSearch()).addToBackStack(null) .commit(); } }, 100); } if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_ADD)) { widgetAdd(); } } } }
From source file:cs.man.ac.uk.tavernamobile.fragments.SearchResultFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { // remove menu added by previous fragment for (int i = 1; i < menu.size(); i++) { menu.removeItem(menu.getItem(i).getItemId()); }//from w w w.j ava 2 s . com parentActivity.getMenuInflater().inflate(R.menu.search_results_screen, menu); LinearLayout searchView = (LinearLayout) menu.findItem(R.id.search_results_search).getActionView(); final EditText query = (EditText) searchView.getChildAt(0); query.requestFocus(); query.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { searchQuery = query.getText().toString(); search(searchQuery); return true; } return false; } }); ImageButton searchButton = (ImageButton) searchView.getChildAt(1); searchButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(android.view.View v) { searchQuery = query.getText().toString(); search(searchQuery); } }); super.onPrepareOptionsMenu(menu); }
From source file:com.nextgis.mobile.fragment.AttributesFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (item.getItemId() == R.id.menu_about || item.getItemId() == R.id.menu_settings) { continue; }/*from w w w .java2 s .c o m*/ item.setVisible(false); } super.onPrepareOptionsMenu(menu); }
From source file:com.example.carrie.carrie_test1.druginfo.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_druginfo); Bundle bundle = getIntent().getExtras(); my_id = bundle.getString("my_id");//get id my_google_id = bundle.getString("my_google_id");//get google_ id my_mon_id = bundle.getString("my_supervise_id"); m_calid = bundle.getString("m_calid", "not found"); Log.d("qqqqq", m_calid); btmbar = (RelativeLayout) findViewById(R.id.btmbar); if (my_id.equals("0") && my_google_id.equals("0") && my_mon_id.equals("0")) { //??????? btmbar.setVisibility(View.GONE); } else {//w ww . j av a 2 s . c o m BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavView_Bar); BottomNavigationViewHelper.disableShiftMode(bottomNavigationView); Menu menu = bottomNavigationView.getMenu(); MenuItem menuItem = menu.getItem(3); menuItem.setChecked(true); bottomNavigationView.setOnNavigationItemSelectedListener( new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.ic_list: Intent intent0 = new Intent(druginfo.this, Choice.class); Bundle bundle0 = new Bundle(); bundle0.putString("memberid", my_id); bundle0.putString("my_google_id", my_google_id); bundle0.putString("my_supervise_id", my_mon_id); intent0.putExtras(bundle0); // put??? startActivity(intent0); break; case R.id.ic_eye: Intent intent1 = new Intent(druginfo.this, MonitorActivity.class); Bundle bundle1 = new Bundle(); bundle1.putString("my_id", my_id); bundle1.putString("my_google_id", my_google_id); bundle1.putString("my_supervise_id", my_mon_id); intent1.putExtras(bundle1); startActivity(intent1); break; case R.id.ic_home: Intent intent2 = new Intent(druginfo.this, MainActivity.class); Bundle bundle2 = new Bundle(); bundle2.putString("googleid", my_google_id); intent2.putExtras(bundle2); startActivity(intent2); break; case R.id.ic_information: Intent intent3 = new Intent(druginfo.this, druginfo.class); Bundle bundle3 = new Bundle(); bundle3.putString("my_id", my_id); bundle3.putString("my_google_id", my_google_id); bundle3.putString("my_supervise_id", my_mon_id); intent3.putExtras(bundle3); startActivity(intent3); break; case R.id.ic_beacon: Intent intent4 = new Intent(druginfo.this, Beacon.class); Bundle bundle4 = new Bundle(); bundle4.putString("my_id", my_id); bundle4.putString("my_google_id", my_google_id); bundle4.putString("my_supervise_id", my_mon_id); intent4.putExtras(bundle4); startActivity(intent4); break; } return false; } }); } listView = (ListView) findViewById(R.id.listview); editText = (EditText) findViewById(R.id.textsearch); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (!s.toString().equals("")) { //reset listview // recyclerView = (RecyclerView) findViewById(R.id.recycler_view); // data_list = new ArrayList<>(); // load_data_from_server(0); // // gridLayoutManager = new GridLayoutManager(getBaseContext(), 2); // recyclerView.setLayoutManager(gridLayoutManager); // // adapter = new CustomAdapter2(getBaseContext(), data_list); // recyclerView.setAdapter(adapter); // // recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { // @Override // public void onScrolled(RecyclerView recyclerView, int dx, int dy) { // // if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) { // load_data_from_server(data_list.get(data_list.size() - 1).getId()); // } // // } // }); recyclerView = (RecyclerView) findViewById(R.id.recycler_view); data_list2 = new ArrayList<>(); Log.d("searchtest", "3"); load_data_from_server_search(s.toString()); Log.d("searchtest", "1"); gridLayoutManager = new GridLayoutManager(getBaseContext(), 2); recyclerView.setLayoutManager(gridLayoutManager); Log.d("searchtest", "2"); adapter = new CustomAdapter2(getBaseContext(), data_list2, m_calid); recyclerView.setAdapter(adapter); } else { recyclerView = (RecyclerView) findViewById(R.id.recycler_view); gridLayoutManager = new GridLayoutManager(getBaseContext(), 2); recyclerView.setLayoutManager(gridLayoutManager); adapter = new CustomAdapter2(getBaseContext(), data_list, m_calid); recyclerView.setAdapter(adapter); } } @Override public void afterTextChanged(Editable s) { } }); recyclerView = (RecyclerView) findViewById(R.id.recycler_view); data_list = new ArrayList<>(); load_data_from_server(0); gridLayoutManager = new GridLayoutManager(this, 2); recyclerView.setLayoutManager(gridLayoutManager); adapter = new CustomAdapter2(this, data_list, m_calid); recyclerView.setAdapter(adapter); recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) { load_data_from_server(data_list.get(data_list.size() - 1).getId()); } } }); }
From source file:com.kanedias.vanilla.lyrics.LyricsShowActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); switch (item.getItemId()) { case R.id.reload_option: // show only when loading is complete item.setVisible(mSwitcher.getDisplayedChild() == 1); continue; default:/*w ww . jav a 2 s . c o m*/ break; } } return super.onPrepareOptionsMenu(menu); }
From source file:com.mobicage.rogerthat.NewsActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); switch (item.getItemId()) { case R.id.saved: item.setVisible(newsStore != null && newsStore.countNewsPinnedItems(feedName) > 0); break; }/*ww w . j a va 2s . c om*/ } return super.onPrepareOptionsMenu(menu); }