Java Code Examples for android.view.MenuItem.equals()

The following are Jave code examples for showing how to use equals() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GoSCELE   File: MainActivity.java   View Source Code Vote up 6 votes
private void selectMenu(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.action_home:
                currentFragment = HomeFragment.newInstance();
                break;
            case R.id.action_course:
                currentFragment = CourseFragment.newInstance();
                break;
            case R.id.action_schedule:
                currentFragment = ScheduleFragment.newInstance();
                break;
            case R.id.action_about:
                currentFragment = AboutFragment.newInstance();
                break;
        }

        if (currentItem == null || !item.equals(currentItem)) {
            item.setChecked(true);
            FragmentTransaction beginTransaction = getSupportFragmentManager().beginTransaction();
            beginTransaction.replace(R.id.container, currentFragment);
            beginTransaction.commit();
        }
        currentItem = item;
    }
 
Example 2
Project: Runnest   File: SideBarActivity.java   View Source Code Vote up 4 votes
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    if (isRunning && !item.equals(runItem)) {
        dialogQuitRun(item);
        return false;
    }

    if (!(isRunning && item.equals(runItem))) {

        if (itemStack.isEmpty() || !itemStack.peek().equals(item)) {
            itemStack.push(item);
        }

        showSearchBar();

        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_profile) {
            toolbar.setTitle("Profile");
            launchFragment(new ProfileFragment());
        } else if (id == R.id.nav_run) {
            toolbar.setTitle("Run");
            hideSearchBar();
            launchFragment(new RunningMapFragment());
        } else if (id == R.id.nav_new_challenge) {
            toolbar.setTitle("Search someone");
            launchFragment(new EmptySearchFragment());

            searchView.setQueryHint("Search someone");
            searchViewAsMenuItem.expandActionView();
        } else if (id == R.id.nav_messages) {
            toolbar.setTitle("Challenges");
            launchFragment(new MessagesFragment());
        } else if (id == R.id.nav_history) {
            toolbar.setTitle("History");
            launchFragment(new HistoryFragment());
        } else if (id == R.id.nav_logout) {
            itemStack.pop();
            dialogLogout();
        }
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}