Example usage for android.view MenuItem setChecked

List of usage examples for android.view MenuItem setChecked

Introduction

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

Prototype

public MenuItem setChecked(boolean checked);

Source Link

Document

Control whether this item is shown with a check mark.

Usage

From source file:edu.nd.darts.cimon.NDroidAdmin.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    try {/*from  www . j av a2  s  .c  o m*/
        inflater.inflate(R.menu.options_menu, menu);
    } catch (InflateException e) {
        e.printStackTrace();
        return false;
    }
    MenuItem item = menu.findItem(R.id.startup);
    if (item != null) {
        SharedPreferences appPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
        boolean startup = appPrefs.getBoolean(PREF_STARTUP, true);
        item.setChecked(startup);
    }
    return true;
}

From source file:com.androguide.honamicontrol.soundcontrol.SoundFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.link_seekbars:
        SharedPreferences soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
        if (item.isChecked()) {
            item.setChecked(false);
            soundPrefs.edit().putBoolean("LINKED", false).commit();
        } else {/*from   ww  w.ja  v  a 2  s .  c o m*/
            item.setChecked(true);
            soundPrefs.edit().putBoolean("LINKED", true).commit();
        }
        break;

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.emotion.emotioncontrol.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_show_drawer_icon) {
        boolean checked = item.isChecked();
        item.setChecked(!checked);
        setLauncherIconEnabled(!checked);
        return true;
    }/*from www .  j  a va  2  s .  c o m*/
    return super.onOptionsItemSelected(item);
}

From source file:com.fjoglar.etsitnoticias.view.activities.BookmarksListActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//from   w  w  w . j  a v  a 2s  . c o  m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.list_navigation_menu_item:
                menuItem.setChecked(true);
                mBackToListActivity = true;
                onBackPressed();
                break;
            case R.id.bookmarks_navigation_menu_item:
                // Do nothing, we're already on that screen
                menuItem.setChecked(true);
                break;
            case R.id.settings_navigation_menu_item:
                Navigator.getInstance().navigateToSettings(getContext());
                overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
                break;
            case R.id.about_navigation_menu_item:
                Navigator.getInstance().navigateToAbout(getContext());
                overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
                break;
            default:
                break;
            }
            // Close the navigation drawer when an item is selected.
            drawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:android.support.design.internal.BottomNavigationMenuView.java

void tryRestoreSelectedItemId(int itemId) {
    final int size = mMenu.size();
    for (int i = 0; i < size; i++) {
        MenuItem item = mMenu.getItem(i);
        if (itemId == item.getItemId()) {
            mSelectedItemId = itemId;//from  w  ww.  j a v  a 2s . c om
            mSelectedItemPosition = i;
            item.setChecked(true);
            break;
        }
    }
}

From source file:com.physphil.android.unitconverterultimate.MainActivity.java

/**
 * Setup navigation drawer//from w w  w  .  j a  va  2s  .c  o m
 * @param state index of item to be selected initially
 */
private void setupDrawer(int state) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_drawer);
    navigationView.getMenu().getItem(state).setChecked(true);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            mDrawerLayout.closeDrawers();
            switch (menuItem.getItemId()) {
            case R.id.drawer_settings:
                PreferencesActivity.start(MainActivity.this);
                return true;

            default:
                menuItem.setChecked(true);
                int conversion = getConversionFromDrawer(menuItem.getItemId());
                setToolbarTitle(mConversions.getById(conversion).getLabelResource());
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.fragment_container, ConversionFragment.newInstance(conversion)).commit();
                return true;
            }
        }
    });
}

From source file:com.bestbeforeapp.parsemvp.notes.NotesActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//from  w  w  w  . ja v  a2  s. com
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.statistics_navigation_menu_item:
                startActivity(new Intent(NotesActivity.this, StatisticsActivity.class));
                break;
            default:
                break;
            }
            // Close the navigation drawer when an item is selected.
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:org.addhen.smssync.presentation.view.ui.activity.MainActivity.java

public void launchIntegration() {
    final MenuItem menuItem = mNavigationView.getMenu().findItem(R.id.nav_integration);
    menuItem.setChecked(true);
    setToolbarTitle(menuItem);//from   w w w.ja v  a2s .  c  om
    replaceFragment(R.id.fragment_main_content, IntegrationFragment.newInstance(), INTEGRATION_TAG);
}

From source file:com.murati.oszk.audiobook.ui.ActionBarCastActivity.java

private void populateDrawerItems(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override// w  w  w .  j av  a  2 s  .c  o m
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            menuItem.setChecked(true);
            mItemToOpenWhenDrawerCloses = menuItem.getItemId();
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
    if (MusicPlayerActivity.class.isAssignableFrom(getClass())) {
        navigationView.setCheckedItem(R.id.navigation_allmusic);
    } else if (SettingsActivity.class.isAssignableFrom(getClass())) {
        navigationView.setCheckedItem(R.id.navigation_playlists);
    }
}

From source file:com.app4am.app4am.LatestNewsListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem item = menu.findItem(R.id.action_catalog);
    if (item != null) {
        boolean checked = item.isChecked();
        Log.d("checked", "state: " + checked + ", internal checked: " + checkedState);
        item.setChecked(checkedState);
    }//  w  w w.j  a  v  a2s .  c  o  m
}