Example usage for android.view MenuItem getItemId

List of usage examples for android.view MenuItem getItemId

Introduction

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

Prototype

public int getItemId();

Source Link

Document

Return the identifier for this menu item.

Usage

From source file:com.golfwallet.main.MainActivity.java

/**   
 *  \brief//ww w.j  a va  2  s  . com
 *    Method called when the user click on a menu item.
 *    \param item An item of the menu
 *    \return Say if the action of selection is made correctly or not
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        Toast.makeText(MainActivity.this, "Settings clicked", Toast.LENGTH_SHORT).show();
        Intent apiTestIntent = new Intent(MainActivity.this, APITest.class);
        MainActivity.this.startActivity(apiTestIntent);
        return true;
    } else if (id == R.id.action_logout) {
        if (ReadWriteData.getConnectionState(context)) {
            Toast.makeText(MainActivity.this, "Bye bye !", Toast.LENGTH_SHORT).show();

            item.setTitle("Login");
            setConnected(false);
        } else {
            item.setTitle("Logout");
            Intent loginIntent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(loginIntent);
            finish();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:net.mEmoZz.PopMovies.frags.MoviesFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
    case R.id.action_pop:
        if (pop.isChecked()) {
            return false;
        } else {//  www  . j ava 2s  .c o m
            pop.setChecked(true);
            movies.clear();
            adapter.clear();
            fullTask("popularity.desc");
            adapter.notifyDataSetChanged();
            gridView.setAdapter(adapter);
        }
        break;
    case R.id.action_high:
        if (high.isChecked()) {
            return false;
        } else {
            high.setChecked(true);
            movies.clear();
            if (adapter != null) {
                adapter.clear();
                fullTask("vote_average.desc");
                adapter.notifyDataSetChanged();
                gridView.setAdapter(adapter);
            }
        }
        break;
    case R.id.action_fav:
        if (fav.isChecked()) {
            return false;
        } else {
            fav.setChecked(true);
            dbTask();
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:eu.thecoder4.gpl.pleftdroid.PleftDroidActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case DELETE_ID:
        final long aid;
        aid = info.id;//  w  ww  .j  av  a2  s . c  o  m
        new AlertDialog.Builder(this).setTitle(R.string.dialog_title_deleteappt)
                .setMessage(R.string.dialog_msg_deleteappt)
                .setPositiveButton(android.R.string.ok, new OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        // Proceed and delete this
                        mDbAdapter.open();
                        mDbAdapter.deleteAppointment(aid);
                        mDbAdapter.close();
                        fillList();
                    }
                }).setNegativeButton(android.R.string.cancel, new OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        // Do nothing
                    }
                }).show();

        return true;
    }

    return super.onContextItemSelected(item);
}

From source file:com.vrem.wifianalyzer.navigation.NavigationMenuViewTest.java

@Test
public void testNavigationMenuView() throws Exception {
    // execute//from  w  w w.  jav  a  2s.c  o m
    final Menu menu = navigationView.getMenu();
    // validate
    assertEquals(NavigationMenu.values().length, menu.size());
    IterableUtils.forEach(EnumUtils.values(NavigationGroup.class), new Closure<NavigationGroup>() {
        @Override
        public void execute(final NavigationGroup navigationGroup) {
            IterableUtils.forEach(navigationGroup.getNavigationMenus(), new Closure<NavigationMenu>() {
                @Override
                public void execute(NavigationMenu navigationMenu) {
                    MenuItem actual = menu.getItem(navigationMenu.ordinal());
                    assertEquals(navigationGroup.ordinal(), actual.getGroupId());
                    assertEquals(mainActivity.getResources().getString(navigationMenu.getTitle()),
                            actual.getTitle());
                    assertEquals(navigationMenu.ordinal(), actual.getItemId());
                    assertEquals(navigationMenu.ordinal(), actual.getOrder());
                }
            });
        }
    });
}

From source file:com.cubic9.android.droidglove.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case Menu.FIRST:
        Intent intent = new Intent(Main.this, Settings.class);
        startActivityForResult(intent, 0);
        return true;
    }//from  w  ww.  j  av  a2  s. c  o m

    return super.onOptionsItemSelected(item);
}

From source file:csic.ceab.movelab.beepath.MainActivity.java

@SuppressWarnings("deprecation")
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_EXIT:
        showDialog(EXIT_DIALOG);/*w  ww . j  av a  2 s  . c  o m*/
        break;
    }
    return true;
}

From source file:com.sutromedia.android.core.PhotoActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.menu.photos) {
        if (isSubsetOnEntry()) {
            onReceiveEntry(new NavigationPhoto());
        }/*w  w w . ja  va2s .  com*/
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:net.stefanopallicca.android.awsmonitor.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_settings) {
        Intent i = new Intent(this, SettingsActivity.class);
        startActivityForResult(i, 1);//from   ww w .java  2  s .  c  o m
    }

    return true;
}

From source file:com.galois.qrstream.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_settings) {
        showFragment(settingsFragment, true);
        // remove the delayed hideUI
        getWindow().getDecorView().getHandler().removeCallbacksAndMessages(HANDLER_TOKEN_HIDE_UI);
        // Hide now
        hideUI();/*from  ww w .  ja  v  a  2  s .  co  m*/
        return true;
    }
    if (currentFragment == settingsFragment && id == android.R.id.home) {
        showFragment(lastFragment, true);
    }
    return super.onOptionsItemSelected(item);
}