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:com.scooter1556.sms.android.activity.ActionBarCastActivity.java

private void populateDrawerItems(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//  w w  w .ja v a2 s  .c o  m
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            menuItem.setChecked(true);
            selectedDrawerItem = menuItem.getItemId();
            drawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:com.bayapps.android.robophish.ui.ActionBarCastActivity.java

private void populateDrawerItems(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from   w ww. java2  s. c o  m*/
        public boolean onNavigationItemSelected(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 (PlaceholderActivity.class.isAssignableFrom(getClass())) {
        navigationView.setCheckedItem(R.id.navigation_playlists);
    }
}

From source file:fr.cph.chicago.core.activity.MainActivity.java

@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
    menuItem.setChecked(true);
    currentPosition = menuItem.getItemId();
    itemSelection(currentPosition);//  w  w w.  jav a2s. com
    return true;
}

From source file:com.smartx.bill.mepad.mestore.uimgloader.AbsListViewBaseActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem pauseOnScrollItem = menu.findItem(R.id.item_pause_on_scroll);
    pauseOnScrollItem.setVisible(true);//from  w w  w .  j a  va2s .c om
    pauseOnScrollItem.setChecked(pauseOnScroll);

    MenuItem pauseOnFlingItem = menu.findItem(R.id.item_pause_on_fling);
    pauseOnFlingItem.setVisible(true);
    pauseOnFlingItem.setChecked(pauseOnFling);
    return true;
}

From source file:com.marshalchen.common.demoofui.stickygridheadersexample.StickGridItemListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_toggle_sticky:
        item.setChecked(!item.isChecked());
        ((StickyGridHeadersGridView) mGridView)
                .setAreHeadersSticky(!((StickyGridHeadersGridView) mGridView).areHeadersSticky());

        return true;
    case R.id.menu_use_list_adapter:
        mGridView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.stickygridheader_item,
                getResources().getStringArray(R.array.countries)));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(false);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(false);
        return true;
    case R.id.menu_use_sticky_adapter:
        mGridView.setAdapter(new StickyGridHeadersSimpleArrayAdapter<String>(
                getActivity().getApplicationContext(), getResources().getStringArray(R.array.countries),
                R.layout.stickygridheader_header, R.layout.stickygridheader_item));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(true);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(false);
        return true;

    default:// w w  w.  jav a  2  s. co m
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.tonicartos.stickygridheadersexample.ItemListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_toggle_sticky:
        item.setChecked(!item.isChecked());
        ((StickyGridHeadersGridView) mGridView)
                .setAreHeadersSticky(!((StickyGridHeadersGridView) mGridView).areHeadersSticky());

        return true;
    case R.id.menu_use_list_adapter:
        mGridView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.item,
                getResources().getStringArray(R.array.countries)));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(false);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(false);
        return true;
    case R.id.menu_use_sticky_adapter:
        mGridView.setAdapter(//from w w  w  .java 2  s.c  o m
                new StickyGridHeadersSimpleArrayAdapter<String>(getActivity().getApplicationContext(),
                        getResources().getStringArray(R.array.countries), R.layout.header, R.layout.item));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(true);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(false);
        return true;

    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.appsummary.luoxf.myappsummary.MainActivity.java

private void setupDrawerLayout() {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//from   w  ww.  j av a 2  s . c  o  m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            int itemid = menuItem.getItemId();
            //                Snackbar.make(content, menuItem.getTitle() + " pressed", Snackbar.LENGTH_LONG).show();
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            switch (itemid) {
            case R.id.drawer_recycler_view:
                startActivity(new Intent(MainActivity.this, RecyclerViewMainActivity.class));
                break;
            case R.id.drawer_animation:
                startActivity(new Intent(MainActivity.this, AnimationMainActivity.class));
                break;
            case R.id.drawer_navigationTabStrip:
                startActivity(new Intent(MainActivity.this, NavigationTabStripActivity.class));
                break;
            case R.id.drawer_more:
                startActivity(new Intent(MainActivity.this, MoreMainActivity.class));
                break;
            default:
                break;
            }
            return true;
        }
    });
}

From source file:com.michael.openexercise.mc_customview.stickygridheaders.StickyItemListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_toggle_sticky:
        item.setChecked(!item.isChecked());
        ((StickyGridHeadersGridView) mGridView)
                .setAreHeadersSticky(!((StickyGridHeadersGridView) mGridView).areHeadersSticky());

        return true;
    case R.id.menu_use_list_adapter:
        mGridView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.sticky_item,
                getResources().getStringArray(R.array.countries)));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(false);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(false);
        return true;
    case R.id.menu_use_sticky_adapter:
        mGridView.setAdapter(new StickyGridHeadersSimpleArrayAdapter<String>(
                getActivity().getApplicationContext(), getResources().getStringArray(R.array.countries),
                R.layout.sticky_header, R.layout.sticky_item));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(true);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(false);
        return true;

    default:/*from w  w w.  j  a  v a  2s.  com*/
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.giovanniterlingen.windesheim.view.ScheduleActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from  w  w  w  .ja v  a 2 s  .  c o  m*/
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            switch (menuItem.getItemId()) {
            case R.id.manage_schedules:
                Intent intent = new Intent(ScheduleActivity.this, ManageSchedulesActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.natschool:
                new CookieController().checkCookieAndIntent(ScheduleActivity.this, false);
                break;
            case R.id.educator:
                new CookieController().checkCookieAndIntent(ScheduleActivity.this, true);
                break;
            case R.id.downloads:
                Intent intent1 = new Intent(ScheduleActivity.this, DownloadsActivity.class);
                startActivity(intent1);
                break;
            case R.id.restore_lessons:
                Intent intent4 = new Intent(ScheduleActivity.this, HiddenLessonsActivity.class);
                startActivity(intent4);
                break;
            case R.id.about:
                Intent intent3 = new Intent(ApplicationLoader.applicationContext, AboutActivity.class);
                startActivity(intent3);
                break;
            case R.id.settings:
                Intent intent5 = new Intent(ApplicationLoader.applicationContext, SettingsActivity.class);
                startActivity(intent5);
                break;

            }
            menuItem.setChecked(false);
            return true;
        }
    });
}

From source file:com.adkdevelopment.e_contact.PagerActivity.java

/**
 * Initialises Navigation Drawer and adds links movement to the footer
 * sets listener on an item click in the Drawer
 *//*from   w ww .j a  v a 2s  . c o  m*/
private void initNavigationDrawer() {
    // Make links work in the Drawer
    mFooterLinks.setMovementMethod(LinkMovementMethod.getInstance());

    // add listener to the buttons in the navigation drawer
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {

            if (item.getItemId() == R.id.drawer_map) {
                item.setChecked(false);
                mDrawerLayout.closeDrawers();
                if (Utilities.checkPlayServices(PagerActivity.this)) {
                    Intent intent = new Intent(PagerActivity.this, MapsActivity.class);
                    startActivity(intent);
                    return true;
                } else {
                    item.setChecked(false);
                    return true;
                }
            } else {
                item.setChecked(true);
                mDrawerLayout.closeDrawers();
                return true;
            }
        }
    });
}