android.view.MenuItem#getItemId ( )源码实例Demo

下面列出了android.view.MenuItem#getItemId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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;
}
 
源代码2 项目: android-dev-challenge   文件: SettingsActivity.java
@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);
}
 
@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);
}
 
源代码4 项目: commcare-android   文件: FormRecordListActivity.java
@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);
}
 
源代码5 项目: android_coursera_1   文件: PlaceViewActivity.java
@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);
	}
}
 
源代码6 项目: JianDan_OkHttpWithVolley   文件: VideoFragment.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.action_refresh) {
        mSwipeRefreshLayout.setRefreshing(true);
        mAdapter.loadFirst();
        return true;
    }
    return false;
}
 
源代码7 项目: flopsydroid   文件: MenuGridViewPagerAdapter.java
@Override
public boolean isViewFromObject(View view, Object o) {
    MenuItem item = (MenuItem) o;

    int tag = (Integer)view.getTag();
    return item.getItemId() == tag;
}
 
源代码8 项目: Phonograph   文件: PlayingQueueAdapter.java
@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);
}
 
源代码9 项目: Pix-Art-Messenger   文件: ActionBarActivity.java
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
源代码10 项目: explorer   文件: MainActivity.java
@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);
    }
}
 
源代码11 项目: Onosendai   文件: MainActivity.java
@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);
	}
}
 
源代码12 项目: ZXing-Standalone-library   文件: HistoryActivity.java
@Override
public boolean onContextItemSelected(MenuItem item) {
  int position = item.getItemId();
  historyManager.deleteHistoryItem(position);
  reloadHistoryItems();
  return true;
}
 
@Override
public boolean onOptionsItemSelected(MenuItem menu) {
	switch (menu.getItemId()) {
	case android.R.id.home:
		quitAlert(this);
		break;

	default:
		break;
	}

	return true;
}
 
源代码14 项目: droidkaigi2016   文件: SearchedSessionsActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
    }
    return super.onOptionsItemSelected(item);
}
 
源代码15 项目: CrepeCake   文件: 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();

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

    return super.onOptionsItemSelected(item);
}
 
源代码16 项目: PKUCourses   文件: CourseActionsActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return true;
    }

    return (super.onOptionsItemSelected(item));
}
 
源代码17 项目: android-tv-leanback   文件: 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) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
@Override
public boolean onOptionsItemSelected(MenuItem item) {

  if (item.getItemId() == android.R.id.home) {
    onBackPressed();
  }
  return super.onOptionsItemSelected(item);
}
 
源代码19 项目: narrate-android   文件: DeveloperPreferences.java
@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);
    }
}
 
源代码20 项目: Audinaut   文件: SubsonicFragment.java
@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;
}