List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:ch.ccapps.android.zeneggen.MainActivity.java
private void setupDrawerContent(@NonNull NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//w ww. jav a 2 s. c om public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { if (menuItem.getItemId() == R.id.nav_home) { Log.i(TAG, "home clicked"); setViewPagerEvents(); } else if (menuItem.getItemId() == R.id.nav_hotels) { Log.i(TAG, "hotels clicked"); setupViewPager(); } menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadListFragment.java
/** * Determines which sorting method was selected and calls the appropriate * sorting method on our list of threads. *///from w w w . ja v a 2 s . c o m @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.thread_sort_date_new: // User wants to push new threads to the top. item.setChecked(true); prefManager.setThreadSort(SortUtil.SORT_DATE_NEWEST); SortUtil.sortThreads(SortUtil.SORT_DATE_NEWEST, ThreadList.getThreads()); adapter.notifyDataSetChanged(); return true; case R.id.thread_sort_date_old: // User wants to push old threads to the top. item.setChecked(true); prefManager.setThreadSort(SortUtil.SORT_DATE_OLDEST); SortUtil.sortThreads(SortUtil.SORT_DATE_OLDEST, ThreadList.getThreads()); adapter.notifyDataSetChanged(); return true; case R.id.thread_sort_score_high: // User wants threads with high relevance/score at the top. item.setChecked(true); prefManager.setThreadSort(SortUtil.SORT_USER_SCORE_HIGHEST); SortUtil.setThreadSortGeo(new GeoLocation(locationListener)); SortUtil.sortThreads(SortUtil.SORT_USER_SCORE_HIGHEST, ThreadList.getThreads()); adapter.notifyDataSetChanged(); return true; case R.id.thread_sort_score_low: // User wants threads with low relevance/score at the top. item.setChecked(true); prefManager.setThreadSort(SortUtil.SORT_USER_SCORE_LOWEST); SortUtil.setThreadSortGeo(new GeoLocation(locationListener)); SortUtil.sortThreads(SortUtil.SORT_USER_SCORE_LOWEST, ThreadList.getThreads()); adapter.notifyDataSetChanged(); return true; case R.id.thread_sort_location: // User wants threads close to a selected location at the top. item.setChecked(true); locSortFlag = 1; this.getSortingLoc(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.oddsoft.tpetrash2.view.activity.MainActivity.java
private void initDrawer() { navigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*w w w.j av a 2s . c o m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { //Checking if the item is in checked state or not, if not make it in checked state if (menuItem.isChecked()) menuItem.setChecked(false); else menuItem.setChecked(true); //Closing drawer on item click drawerLayout.closeDrawers(); switch (menuItem.getItemId()) { case R.id.navSetting: startActivity(new Intent(MainActivity.this, Prefs.class)); break; case R.id.navAbout: new LibsBuilder() //provide a style (optional) (LIGHT, DARK, LIGHT_DARK_TOOLBAR) .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).withAboutIconShown(true) .withAboutVersionShown(true).withAboutAppName(getString(R.string.app_name)) .withActivityTitle(getString(R.string.about)) .withAboutDescription(getString(R.string.license)) //start the activity .start(MainActivity.this); break; case R.id.navSuggest: startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.oddsoft.tpetrash2"))); break; case R.id.navFacebook: startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/TaipeiTrash"))); break; } return false; } }); actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.app_name, R.string.app_name) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank super.onDrawerOpened(drawerView); } }; //Setting the actionbarToggle to drawer layout drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:com.app4am.app4am.LatestNewsListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_search: Toast.makeText(getActivity(), "frag action_search", Toast.LENGTH_SHORT).show(); return true; case R.id.action_catalog: item.setChecked(true); checkedState = !checkedState;/*from w w w . j a v a2 s . co m*/ getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() Toast.makeText(getActivity(), "frag action_catalog", Toast.LENGTH_SHORT).show(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.zyascend.RecompileToDo.view.statisticstasks.StatisticsActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from w w w . j a v a 2 s.com public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.list_navigation_menu_item: Intent intent = new Intent(StatisticsActivity.this, TasksActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); break; default: break; } item.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:net.hyx.app.volumenotification.ActivityMain.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; case R.id.menu_pref: startActivity(new Intent(this, ActivityPref.class)); return true; case R.id.menu_dark_app_theme: boolean dark_theme = !item.isChecked(); settings.edit().putBoolean("pref_dark_app_theme", dark_theme).apply(); item.setChecked(dark_theme); setTheme(settings.getAppTheme()); recreate();/*from w w w. j a va 2 s. com*/ return true; case R.id.menu_about: Uri url = Uri.parse(getResources().getString(R.string.menu_about_url)); startActivity(new Intent(Intent.ACTION_VIEW, url)); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.rsamadhan.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from ww w. j a v a 2 s .c om public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.nav_change_lan) { navigateToLanguageChange(); } else if (menuItem.getItemId() == R.id.nav_stats) { Intent intent = new Intent(MainActivity.this, BarActivity.class); startActivity(intent); } menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:io.github.sin3hz.fastjumper.sample.AppListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_use_divider: { mUseDivider = !item.isChecked(); item.setChecked(mUseDivider); setupDivider();/* w w w . ja va2 s. c o m*/ return true; } case R.id.action_load_more: { mLoadMore = !item.isChecked(); return true; } default: return super.onOptionsItemSelected(item); } }
From source file:org.appspot.apprtc.my.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from ww w . ja v a 2 s . c om public boolean onNavigationItemSelected(MenuItem menuItem) { // menuItem.getItemId(); Log.d("??", String.valueOf(menuItem.getItemId())); Log.d("??", "??"); menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:io.github.protino.codewatch.ui.NavigationDrawerActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Icepick.restoreInstanceState(this, savedInstanceState); setContentView(R.layout.activity_navigation_drawer); ButterKnife.bind(this); setSupportActionBar(toolbar);/* ww w . jav a 2 s .c o m*/ sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if (savedInstanceState == null) { firebaseUid = sharedPreferences.getString(Constants.PREF_FIREBASE_USER_ID, null); String basicData = sharedPreferences.getString(Constants.PREF_BASIC_USER_DETAILS, null); basicUserData = new Gson().fromJson(basicData, ProfileData.class); MenuItem item = navigationView.getMenu().findItem(R.id.dashboard); onNavigationItemSelected(item); item.setChecked(true); } setupDrawer(); mutex.set(0); FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance(); firebaseAnalytics = FirebaseAnalytics.getInstance(this); achievementsDatabaseRef = firebaseDatabase.getReference().child("achv").child(firebaseUid); getLoaderManager().initLoader(RANK_LOADER_ID, null, this); //Internet error snackbar snackbar = Snackbar .make(getWindow().getDecorView(), R.string.internet_error_message, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.retry, new View.OnClickListener() { @Override public void onClick(View view) { displayInternetError(NetworkUtils.isNetworkUp(NavigationDrawerActivity.this)); } }); }