本文整理汇总了Java中android.widget.Spinner.setSelection方法的典型用法代码示例。如果您正苦于以下问题:Java Spinner.setSelection方法的具体用法?Java Spinner.setSelection怎么用?Java Spinner.setSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.Spinner
的用法示例。
在下文中一共展示了Spinner.setSelection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResume
import android.widget.Spinner; //导入方法依赖的package包/类
/**
* Method allows us to retrieve previous selection before the activity was paused
*/
@Override
protected void onResume() {
super.onResume();
try {
/*
* Retrieve the saved spinner selection
*/
spinner = (Spinner) findViewById(R.id.setPin_spinner);
SharedPreferences category_prefs = getSharedPreferences("category_prefs", Context.MODE_PRIVATE);
int spinner_index = category_prefs.getInt("spinner_indx", 0);
spinner.setSelection(spinner_index);
} catch (Exception ex) {
Log.e("Spinner onResume", ex.getMessage(), ex);
}
}
示例2: loadCommandSpinner
import android.widget.Spinner; //导入方法依赖的package包/类
private void loadCommandSpinner(Spinner spinner, Command command) {
AlertTypeItemSelectedListener listener = new AlertTypeItemSelectedListener(command);
spinner.setOnItemSelectedListener(listener);
List<String> list = new ArrayList<String>();
int defaultPos = 0;
int pos = 0;
for (String callableCommand : callableCommandNames) {
int resourceId = getResources().getIdentifier(callableCommand, "string", getPackageName());
if (resourceId != 0) {
list.add(getString(resourceId));
}
else {
list.add(callableCommand);
}
if (callableCommand.equals(command.getMethod())) {
defaultPos = pos;
}
pos++;
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
spinner.setSelection(defaultPos);
}
示例3: fillTrackInstrument
import android.widget.Spinner; //导入方法依赖的package包/类
public void fillTrackInstrument() {
ArrayAdapter<TGSelectableItem> adapter = new ArrayAdapter<TGSelectableItem>(getActivity(), android.R.layout.simple_spinner_item, createSelectableChannels());
Spinner spinner = (Spinner) this.dialogView.findViewById(R.id.track_channel_dlg_channel_value);
spinner.setAdapter(adapter);
spinner.setSelection(adapter.getPosition(new TGSelectableItem(this.songManager.getChannel(this.song, this.track.getChannelId()), null)));
}
示例4: selectSpinnerItemByValue
import android.widget.Spinner; //导入方法依赖的package包/类
/**
*
* @param spnr
* @param value
*
* solution based on an answer from stack overflow
* resource: https://stackoverflow.com/questions/11072576/set-selected-item-of-spinner-programmatically
*
*/
public static void selectSpinnerItemByValue(Spinner spnr, String value) {
ArrayAdapter<String> adapter = (ArrayAdapter<String>) spnr.getAdapter();
String currentItem;
for (int i = 0; i < adapter.getCount(); i++) {
currentItem = adapter.getItem(i);
if(currentItem.equals(value)) {
spnr.setSelection(i);
return;
}
}
}
示例5: setControls
import android.widget.Spinner; //导入方法依赖的package包/类
private void setControls() {
iconNumber = (Spinner) findViewById(R.id.stIconNumber);
List<String> spinnerArray = new ArrayList<>();
spinnerArray.add(String.valueOf(Const.ICONS_SIZE.ICONS_BIG));
spinnerArray.add(String.valueOf(Const.ICONS_SIZE.ICONS_MEDIUM));
spinnerArray.add(String.valueOf(Const.ICONS_SIZE.ICONS_LOW));
spinnerArray.add(String.valueOf(Const.ICONS_SIZE.ICONS_LOWER));
spinnerArray.add(String.valueOf(Const.ICONS_SIZE.ICONS_LOWEST));
spinnerArray.add(String.valueOf(Const.ICONS_SIZE.ICONS_LOWESTER));
spinnerArray.add(String.valueOf(Const.ICONS_SIZE.ICONS_LOWESTEREST));
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.spinner_item, spinnerArray);
iconNumber.setAdapter(adapter);
iconNumber.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
iconNumber.setSelection(selectedPosition, true);
btnChooseWallpaper = (Button) findViewById(R.id.stWallpaperButton);
btnChooseWallpaper.setOnClickListener(this);
btnWallpaperDefault = (Button) findViewById(R.id.stWallpaperButtonDefault);
btnWallpaperDefault.setOnClickListener(this);
txtCustomTitle = (EditText) findViewById(R.id.stCustomTitleValue);
}
示例6: onCreate
import android.widget.Spinner; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_colors);
mColorScheme = HostDatabase.DEFAULT_COLOR_SCHEME;
mHostDb = HostDatabase.get(this);
mColorList = mHostDb.getColorsForScheme(mColorScheme);
mDefaultColors = mHostDb.getDefaultColorsForScheme(mColorScheme);
mColorGrid = (GridView) findViewById(R.id.color_grid);
mColorGrid.setAdapter(new ColorsAdapter(true));
mColorGrid.setOnItemClickListener(this);
mColorGrid.setSelection(0);
mFgSpinner = (Spinner) findViewById(R.id.fg);
mFgSpinner.setAdapter(new ColorsAdapter(false, R.string.colors_fg_label));
mFgSpinner.setSelection(mDefaultColors[0]);
mFgSpinner.setOnItemSelectedListener(this);
mBgSpinner = (Spinner) findViewById(R.id.bg);
mBgSpinner.setAdapter(new ColorsAdapter(false, R.string.color_bg_label));
mBgSpinner.setSelection(mDefaultColors[1]);
mBgSpinner.setOnItemSelectedListener(this);
}
示例7: onCreate
import android.widget.Spinner; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView versionInfoTextView = (TextView) findViewById(R.id.VersionInfoTextView);
String info = "版本号:" + getVersionDescription() + ",编译时间:" + getBuildTimeDescription();
versionInfoTextView.setText(info);
mPreviewSizeRatioSpinner = (Spinner) findViewById(R.id.PreviewSizeRatioSpinner);
mPreviewSizeLevelSpinner = (Spinner) findViewById(R.id.PreviewSizeLevelSpinner);
mEncodingModeLevelSpinner = (Spinner) findViewById(R.id.EncodingModeLevelSpinner);
mEncodingSizeLevelSpinner = (Spinner) findViewById(R.id.EncodingSizeLevelSpinner);
mEncodingBitrateLevelSpinner = (Spinner) findViewById(R.id.EncodingBitrateLevelSpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, RecordSettings.PREVIEW_SIZE_RATIO_TIPS_ARRAY);
mPreviewSizeRatioSpinner.setAdapter(adapter);
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, RecordSettings.PREVIEW_SIZE_LEVEL_TIPS_ARRAY);
mPreviewSizeLevelSpinner.setAdapter(adapter);
mPreviewSizeLevelSpinner.setSelection(3);
adapter= new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, RecordSettings.ENCODING_MODE_LEVEL_TIPS_ARRAY);
mEncodingModeLevelSpinner.setAdapter(adapter);
mEncodingModeLevelSpinner.setSelection(0);
adapter= new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, RecordSettings.ENCODING_SIZE_LEVEL_TIPS_ARRAY);
mEncodingSizeLevelSpinner.setAdapter(adapter);
mEncodingSizeLevelSpinner.setSelection(7);
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, RecordSettings.ENCODING_BITRATE_LEVEL_TIPS_ARRAY);
mEncodingBitrateLevelSpinner.setAdapter(adapter);
mEncodingBitrateLevelSpinner.setSelection(2);
}
示例8: onViewCreated
import android.widget.Spinner; //导入方法依赖的package包/类
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final Spinner spinnerTimer = (Spinner) view.findViewById(R.id.fragment_components_menus_spinner_timer);
final Spinner spinnerWhen = (Spinner) view.findViewById(R.id.fragment_components_menus_spinner_when);
final Spinner spinnerColors = (Spinner) view.findViewById(R.id.fragment_components_menus_spinner_colors);
final SpinnerLayout spinnerLayoutTimer = (SpinnerLayout) view.findViewById(R.id.fragment_components_menus_spinner_layout_timer);
final SpinnerLayout sSpinnerLayoutWhen = (SpinnerLayout) view.findViewById(R.id.fragment_components_menus_spinner_layout_when);
final SpinnerLayout spinnerLayoutColors = (SpinnerLayout) view.findViewById(R.id.fragment_components_menus_spinner_layout_colors);
final SpinnerLayout spinnerLayoutColorsDisabled = (SpinnerLayout) view.findViewById(R.id.fragment_components_menus_spinner_layout_colors_disabled);
final Context context = getActivity();
spinnerTimer.setAdapter(new TimerAdapter(context));
spinnerTimer.setSelection(2, false);
spinnerTimer.setOnItemSelectedListener(this);
spinnerWhen.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, WHEN));
spinnerWhen.setSelection(0, false);
spinnerWhen.setOnItemSelectedListener(this);
spinnerColors.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, COLORS));
spinnerColors.setSelection(0, false);
spinnerColors.setOnItemSelectedListener(this);
spinnerLayoutTimer.setAdapter(new TimerAdapter(context));
spinnerLayoutTimer.setSelection(2, false);
spinnerLayoutTimer.setOnItemSelectedListener(this);
sSpinnerLayoutWhen.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, WHEN));
sSpinnerLayoutWhen.setOnItemSelectedListener(this);
spinnerLayoutColors.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, COLORS));
spinnerLayoutColors.setOnItemSelectedListener(this);
spinnerLayoutColorsDisabled.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, COLORS));
}
示例9: onCreate
import android.widget.Spinner; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_edit_issue);
mIssuename = (EditText) findViewById(R.id.IssueName);
mIssueDesc = (EditText) findViewById(R.id.descriptionTex);
mPosesrisk = (RadioGroup) findViewById(R.id.risk);
mImageView = (ImageView) findViewById(R.id.eventView);
mRisk = false;
mIssueAdapter = AdapterFactory.getInstance().getIssueAdapter(this);
Spinner categorySpinner = (Spinner) findViewById(R.id.nameCategorySpinner);
categorySpinner.setAdapter(new CategorySpinnerAdapter(getApplicationContext(),
R.layout.text_and_icon_spinner_tem));
categorySpinner.setSelection(categorySpinner.getCount());
Intent intent = getIntent();
Bundle data = intent.getBundleExtra(TAG_ISSUE);
mIssue = (Issue) data.getSerializable(TAG_ISSUE);
mIssuename.setText(mIssue.getTitle());
mIssueDesc.setText(mIssue.getDescription());
String url = mIssue.getPicture().getMedUrl();
Glide.with(this).load(url).into(mImageView);
Category[] categories = Category.values();
for (int i = 0; i < categories.length; ++i) {
if (mIssue.getCategory().equals(categories[i])) {
categorySpinner.setSelection(i);
}
}
if (mIssue.isRisk()) {
mPosesrisk.check(R.id.yes);
mRisk = true;
} else mPosesrisk.check(R.id.no);
Toolbar toolbar = (Toolbar) findViewById(R.id.create_issue_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(getString(R.string.edit_issue));
mPosesrisk.setOnCheckedChangeListener(mRadioListener);
mPictureUpdated = false;
setupCloseKeyboard(findViewById(android.R.id.content));
}
示例10: initOutlineSizeSpinner
import android.widget.Spinner; //导入方法依赖的package包/类
private void initOutlineSizeSpinner(float outlineSize) {
Spinner spinner = (Spinner) findViewById(R.id.edit_outline_size);
spinner.setOnItemSelectedListener(this);
String[] sizeList = new String[]{"Thin", "Normal", "Thick"};
spinner.setAdapter(new ArrayAdapter<>(this,
android.R.layout.simple_spinner_dropdown_item, sizeList));
spinner.setSelection(outlineSizeToPosition(outlineSize));
}
示例11: fillData
import android.widget.Spinner; //导入方法依赖的package包/类
public void fillData(View view, int type, int selection) {
TGSelectableItem[] selectableItems = createDataValues(type);
ArrayAdapter<TGSelectableItem> adapter = new ArrayAdapter<TGSelectableItem>(getActivity(), android.R.layout.simple_spinner_item, selectableItems);
Spinner spinner = (Spinner) view.findViewById(R.id.harmonic_dlg_data_value);
spinner.setAdapter(adapter);
spinner.setEnabled(selectableItems.length > 0);
spinner.setVisibility(selectableItems.length > 0 ? View.VISIBLE : View.GONE);
if( selectableItems.length > 0 ) {
spinner.setSelection(adapter.getPosition(new TGSelectableItem(Integer.valueOf(selection), null)));
}
}
示例12: fillCount
import android.widget.Spinner; //导入方法依赖的package包/类
public void fillCount(View view) {
ArrayAdapter<TGSelectableItem> adapter = new ArrayAdapter<TGSelectableItem>(getActivity(), android.R.layout.simple_spinner_item, createCountValues());
Spinner spinner = (Spinner) view.findViewById(R.id.measure_add_dlg_count_value);
spinner.setAdapter(adapter);
spinner.setSelection(adapter.getPosition(new TGSelectableItem(Integer.valueOf(1), null)));
}
示例13: onCreateOptionsMenu
import android.widget.Spinner; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_salaries, menu);
Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.action_category));
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.array_period_date, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setSelection(periodIndex);//set prevision selected period
spinner.setOnItemSelectedListener(onItemSelectedListener);
}
示例14: setupDOBSpinners
import android.widget.Spinner; //导入方法依赖的package包/类
private void setupDOBSpinners () {
dobDaySpinner = (Spinner) findViewById(R.id.dob_day_spinner);
dobMonthSpinner = (Spinner) findViewById(R.id.dob_month_spinner);
dobYearSpinner = (Spinner) findViewById(R.id.dob_year_spinner);
List<String> days = new ArrayList<>();
for (int i = 0; i < 31; i++) {
days.add("" + (i + 1));
}
ArrayAdapter<String> dayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, days);
dayAdapter.setDropDownViewResource(R.layout.spinner_dropdown);
dobDaySpinner.setAdapter(dayAdapter);
ArrayAdapter<CharSequence> monthAdapter = ArrayAdapter.createFromResource(this,
R.array.months_array, android.R.layout.simple_spinner_item);
monthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dobMonthSpinner.setAdapter(monthAdapter);
Date dt = new Date();
List<String> years = new ArrayList<>();
int maxYear = dt.getYear() + 1900 - 18;
for (int i = 1900; i <= maxYear; i++) {
years.add("" + i);
}
ArrayAdapter<String> yearAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, years);
yearAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dobYearSpinner.setAdapter(yearAdapter);
dobYearSpinner.setSelection(DOB_YEAR_STARTING_INDEX);
}
示例15: onCreate
import android.widget.Spinner; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler))
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());
Logger.info("Hello World");
settings = new Settings();
fps = 24;
bnStart = (Button) findViewById(R.id.bnStart);
bnStart.setOnClickListener(bnStartOnClickListener);
bnClose = (Button) findViewById(R.id.bnClose);
bnClose.setOnClickListener(bnCloseOnClickListener);
tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
//Tab 1
TabHost.TabSpec spec = tabHost.newTabSpec("Tab One");
spec.setContent(R.id.tab1);
spec.setIndicator("");
tabHost.addTab(spec);
//Tab 2
spec = tabHost.newTabSpec("Tab Two");
spec.setContent(R.id.tab2);
spec.setIndicator("");
tabHost.addTab(spec);
tvIntervalValue = (TextView) findViewById(R.id.tvIntervalValue);
tvIntervalUnit = (TextView) findViewById(R.id.tvIntervalUnit);
sbInterval = (AdvancedSeekBar) findViewById(R.id.sbInterval);
sbInterval.setMax(83);
sbInterval.setOnSeekBarChangeListener(sbIntervalOnSeekBarChangeListener);
tvShotsValue = (TextView) findViewById(R.id.tvShotsValue);
sbShots = (AdvancedSeekBar) findViewById(R.id.sbShots);
sbShots.setMax(130);
sbShots.setOnSeekBarChangeListener(sbShotsOnSeekBarChangeListener);
tvDurationValue = (TextView) findViewById(R.id.tvDurationValue);
tvDurationUnit = (TextView) findViewById(R.id.tvDurationUnit);
tvVideoTimeValue = (TextView) findViewById(R.id.tvVideoTimeValue);
tvVideoTimeUnit = (TextView) findViewById(R.id.tvVideoTimeUnit);
spnFps = (Spinner) findViewById(R.id.spnFps);
spnFps.setSelection(0);
spnFps.setOnItemSelectedListener(spnFpsOnItemSelectedListener);
cbSilentShutter = (CheckBox) findViewById(R.id.cbSilentShutter);
cbSilentShutter.setOnCheckedChangeListener(cbSilentShutterOnCheckListener);
}