Java Code Examples for android.view.MenuItem#getItemId()

The following examples show how to use android.view.MenuItem#getItemId() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
	final int id = item.getItemId();
	switch (id) {
		case android.R.id.home:
			onBackPressed();
			break;
		case R.id.action_about:
			final AppHelpFragment fragment = AppHelpFragment.getInstance(getAboutTextId());
			fragment.show(getSupportFragmentManager(), "help_fragment");
			break;
		default:
			return onOptionsItemSelected(id);
	}
	return true;
}
 
Example 2
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    /*
     * Normally, calling setDisplayHomeAsUpEnabled(true) (we do so in onCreate here) as well as
     * declaring the parent activity in the AndroidManifest is all that is required to get the
     * up button working properly. However, in this case, we want to navigate to the previous
     * screen the user came from when the up button was clicked, rather than a single
     * designated Activity in the Manifest.
     *
     * We use the up button's ID (android.R.id.home) to listen for when the up button is
     * clicked and then call onBackPressed to navigate to the previous Activity when this
     * happens.
     */
    int id = item.getItemId();
    if (id == android.R.id.home) {
        onBackPressed();
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 3
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.liner_layout:
            mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
            break;

        case R.id.grid_layout:
            mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
            break;
    }
    mDataList.clear();
    getData();
    mRecyclerView.setAdapter(mHeaderAndFooterWrapper);
    return super.onOptionsItemSelected(item);
}
 
Example 4
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case DOWNLOAD_FORMS_FROM_SERVER:
            String source = DeveloperPreferences.getRemoteFormPayloadUrl();
            ArchivedFormRemoteRestore.pullArchivedFormsFromServer(source, this, platform);
            return true;
        case DOWNLOAD_FORMS_FROM_FILE:
            String sourceFile = DeveloperPreferences.getLocalFormPayloadFilePath();
            ArchivedFormRemoteRestore.pullArchivedFormsFromFile(sourceFile, this, platform);
        case MENU_SUBMIT_QUARANTINE_REPORT:
            generateQuarantineReport();
            return true;
        case R.id.barcode_scan_action_bar:
            barcodeScanOnClickListener.onClick(null);
            return true;
        case R.id.menu_settings:
            HomeScreenBaseActivity.createPreferencesMenu(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 5
Source Project: android_coursera_1   File: PlaceViewActivity.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case R.id.print_badges:
		ArrayList<PlaceRecord> currData = mAdapter.getList();
		for (int i = 0; i < currData.size(); i++) {
			log(currData.get(i).toString());
		}
		return true;
	case R.id.delete_badges:
		mAdapter.removeAllViews();
		return true;
	case R.id.place_one:
		mMockLocationProvider.pushLocation(37.422, -122.084);
		return true;
	case R.id.place_invalid:
		mMockLocationProvider.pushLocation(0, 0);
		return true;
	case R.id.place_two:
		mMockLocationProvider.pushLocation(38.996667, -76.9275);
		return true;
	default:
		return super.onOptionsItemSelected(item);
	}
}
 
Example 6
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.action_refresh) {
        mSwipeRefreshLayout.setRefreshing(true);
        mAdapter.loadFirst();
        return true;
    }
    return false;
}
 
Example 7
@Override
public boolean isViewFromObject(View view, Object o) {
    MenuItem item = (MenuItem) o;

    int tag = (Integer)view.getTag();
    return item.getItemId() == tag;
}
 
Example 8
@Override
protected boolean onSongMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_remove_from_playing_queue:
            MusicPlayerRemote.removeFromQueue(getAdapterPosition());
            return true;
    }
    return super.onSongMenuItemClick(item);
}
 
Example 9
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 10
Source Project: explorer   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

        case R.id.action_delete:
            actionDelete();
            return true;

        case R.id.action_rename:
            actionRename();
            return true;

        case R.id.action_search:
            actionSearch();
            return true;

        case R.id.action_copy:
            actionCopy();
            return true;

        case R.id.action_move:
            actionMove();
            return true;

        case R.id.action_send:
            actionSend();
            return true;

        case R.id.action_sort:
            actionSort();
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 11
Source Project: Onosendai   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected (final MenuItem item) {
	switch (item.getItemId()) {
		case android.R.id.home:
			new GotoMenu(this).onClick(this.columnTitleStrip); // TODO FIXME position it correctly under icon.
			return true;
		case R.id.mnuPost:
			showPost();
			return true;
		case R.id.mnuOutbox:
			showOutbox();
			return true;
		case R.id.mnuRefreshColumnNow:
			scheduleRefreshInteractive(getVisibleColumnIds());
			return true;
		case R.id.mnuRefreshAllNow:
			scheduleRefreshInteractive();
			return true;
		case R.id.mnuPreferences:
			startActivity(new Intent(this, OsPreferenceActivity.class));
			return true;
		case R.id.mnuLocalSearch:
			showLocalSearch();
			return true;
		default:
			return super.onOptionsItemSelected(item);
	}
}
 
Example 12
@Override
public boolean onContextItemSelected(MenuItem item) {
  int position = item.getItemId();
  historyManager.deleteHistoryItem(position);
  reloadHistoryItems();
  return true;
}
 
Example 13
@Override
public boolean onOptionsItemSelected(MenuItem menu) {
	switch (menu.getItemId()) {
	case android.R.id.home:
		quitAlert(this);
		break;

	default:
		break;
	}

	return true;
}
 
Example 14
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
    }
    return super.onOptionsItemSelected(item);
}
 
Example 15
Source Project: CrepeCake   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 16
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return true;
    }

    return (super.onOptionsItemSelected(item));
}
 
Example 17
@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) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 18
@Override
public boolean onOptionsItemSelected(MenuItem item) {

  if (item.getItemId() == android.R.id.home) {
    onBackPressed();
  }
  return super.onOptionsItemSelected(item);
}
 
Example 19
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId() ) {
        case android.R.id.home:
            onBackPressed();
            overridePendingTransition(R.anim.ease_in_from_left, R.anim.slide_out_to_right);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 20
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_global_shuffle:
            onShuffleRequested();
            return true;
        case R.id.menu_refresh:
            refresh(true);
            return true;
        case R.id.menu_play_now:
            playNow(false, false, false);
            return true;
        case R.id.menu_play_last:
            playNow(false, true, false);
            return true;
        case R.id.menu_play_next:
            playNow(false, true, true);
            return true;
        case R.id.menu_shuffle:
            playNow(true, false, false);
            return true;
        case R.id.menu_download:
            downloadBackground(false);
            clearSelected();
            return true;
        case R.id.menu_cache:
            downloadBackground(true);
            clearSelected();
            return true;
        case R.id.menu_delete:
            delete();
            clearSelected();
            return true;
        case R.id.menu_add_playlist:
            List<Entry> songs = getSelectedEntries();
            addToPlaylist(songs);
            clearSelected();
            return true;
    }

    return false;
}