本文整理了Java中android.widget.Spinner.setSelection()
方法的一些代码示例,展示了Spinner.setSelection()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spinner.setSelection()
方法的具体详情如下:
包路径:android.widget.Spinner
类名称:Spinner
方法名:setSelection
暂无
代码示例来源:origin: stackoverflow.com
Spinner s = (Spinner)Util.findViewById(view, R.id.sound, R.id.spinner);
s.setAdapter(adapter);
s.setSelection(position, false);
s.setOnItemSelectedListener(listener);
代码示例来源:origin: stackoverflow.com
Spinner sp = (Spinner)findViewById(R.id.spinner);
sp.setSelection(pos);
代码示例来源:origin: novoda/android-demos
void setSelected(int position) {
mView.setSelection(position);
}
代码示例来源:origin: seven332/EhViewer
public void setMinRating(int minRating) {
if (minRating >= 2 && minRating <= 5) {
mSr.setChecked(true);
mMinRating.setSelection(minRating - 2);
} else {
mSr.setChecked(false);
}
}
代码示例来源:origin: cSploit/android
public void onItemSelected(AdapterView<?> adapter,
View view, int position, long id) {
int portIndex = mProtocolAdapter
.getPortIndexByProtocol(position);
if (portIndex != -1)
mPortSpinner.setSelection(portIndex);
}
代码示例来源:origin: stackoverflow.com
public static void selectSpinnerItemByValue(Spinner spnr, long value) {
SimpleCursorAdapter adapter = (SimpleCursorAdapter) spnr.getAdapter();
for (int position = 0; position < adapter.getCount(); position++) {
if(adapter.getItemId(position) == value) {
spnr.setSelection(position);
return;
}
}
}
代码示例来源:origin: ankidroid/Anki-Android
private void updateDeckPosition() {
int position = mAllDeckIds.indexOf(mCurrentDid);
if (position != -1) {
mNoteDeckSpinner.setSelection(position, false);
} else {
Timber.e("updateDeckPosition() error :: mCurrentDid=%d, position=%d", mCurrentDid, position);
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void setupSubtitleSpinner() {
if (getContext() == null) return;
streamsSpinner.setAdapter(subtitleStreamsAdapter);
streamsSpinner.setSelection(selectedSubtitleIndex);
setRadioButtonsState(true);
}
代码示例来源:origin: card-io/card.io-Android-SDK
private void setupLanguageList() {
List<String> languages = new ArrayList<>();
for (SupportedLocale<StringKey> locale : LocalizedStringsList.ALL_LOCALES) {
languages.add(locale.getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, languages);
mLanguageSpinner.setAdapter(adapter);
mLanguageSpinner.setSelection(adapter.getPosition("en"));
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void setupVideoSpinner() {
if (getContext() == null) return;
streamsSpinner.setAdapter(videoStreamsAdapter);
streamsSpinner.setSelection(selectedVideoIndex);
setRadioButtonsState(true);
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void setupAudioSpinner() {
if (getContext() == null) return;
streamsSpinner.setAdapter(audioStreamsAdapter);
streamsSpinner.setSelection(selectedAudioIndex);
setRadioButtonsState(true);
}
代码示例来源:origin: k9mail/k-9
public static void setSpinnerOptionValue(Spinner spinner, Object value) {
for (int i = 0, count = spinner.getCount(); i < count; i++) {
SpinnerOption so = (SpinnerOption)spinner.getItemAtPosition(i);
if (so.value.equals(value)) {
spinner.setSelection(i, true);
return;
}
}
}
代码示例来源:origin: cSploit/android
public void onItemSelected(AdapterView<?> adapter, View view,
int position, long id) {
String port = (String) adapter.getItemAtPosition(position);
int protocolIndex = mProtocolAdapter.getIndexByPort(port);
if (protocolIndex != -1)
mProtocolSpinner.setSelection(protocolIndex);
}
代码示例来源:origin: vinc3m1/RoundedImageView
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.example_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Spinner navSpinner = (Spinner) findViewById(R.id.spinner_nav);
navSpinner.setAdapter(ArrayAdapter.createFromResource(
navSpinner.getContext(),
R.array.action_list,
android.R.layout.simple_spinner_dropdown_item));
navSpinner.setOnItemSelectedListener(this);
if (savedInstanceState == null) {
navSpinner.setSelection(0);
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void setupActionBar(final StreamInfo info) {
if (DEBUG) Log.d(TAG, "setupActionBarHandler() called with: info = [" + info + "]");
boolean isExternalPlayerEnabled = PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(activity.getString(R.string.use_external_video_player_key), false);
sortedVideoStreams = ListHelper.getSortedStreamVideosList(activity, info.getVideoStreams(), info.getVideoOnlyStreams(), false);
selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(activity, sortedVideoStreams);
final StreamItemAdapter<VideoStream, Stream> streamsAdapter = new StreamItemAdapter<>(activity, new StreamSizeWrapper<>(sortedVideoStreams, activity), isExternalPlayerEnabled);
spinnerToolbar.setAdapter(streamsAdapter);
spinnerToolbar.setSelection(selectedVideoStreamIndex);
spinnerToolbar.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedVideoStreamIndex = position;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
代码示例来源:origin: stackoverflow.com
private void setSpinnerSelectionWithoutCallingListener(final Spinner spinner, final int selection) {
final OnItemSelectedListener l = spinner.getOnItemSelectedListener();
spinner.setOnItemSelectedListener(null);
spinner.post(new Runnable() {
@Override
public void run() {
spinner.setSelection(selection);
spinner.post(new Runnable() {
@Override
public void run() {
spinner.setOnItemSelectedListener(l);
}
});
}
});
}
代码示例来源:origin: hidroh/materialistic
@Test
public void test() {
preferenceView.performClick();
((Spinner) preferenceView.findViewById(R.id.spinner)).setSelection(selection);
assertNotNull(Application.TYPE_FACE);
preferenceView.performClick();
((Spinner) preferenceView.findViewById(R.id.spinner)).setSelection(0);
assertNull(Application.TYPE_FACE);
}
代码示例来源:origin: hidroh/materialistic
@Test
public void test() {
preferenceView.performClick();
((Spinner) preferenceView.findViewById(R.id.spinner)).setSelection(selection);
assertThat(Preferences.Theme.resolvePreferredTextSize(activity)).isEqualTo(styleResId);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getSelectedItemShouldReturnCorrectValue(){
spinner.setAdapter(arrayAdapter);
spinner.setSelection(0);
assertThat((String) spinner.getSelectedItem()).isEqualTo("foo");
assertThat((String) spinner.getSelectedItem()).isNotEqualTo("bar");
spinner.setSelection(1);
assertThat((String) spinner.getSelectedItem()).isEqualTo("bar");
assertThat((String) spinner.getSelectedItem()).isNotEqualTo("foo");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setSelectionWithAnimatedTransition() {
spinner.setAdapter(arrayAdapter);
spinner.setSelection(0, true);
assertThat((String) spinner.getSelectedItem()).isEqualTo("foo");
assertThat((String) spinner.getSelectedItem()).isNotEqualTo("bar");
assertThat(shadowSpinner.isAnimatedTransition()).isTrue();
}
内容来源于网络,如有侵权,请联系作者删除!