當前位置: 首頁>>代碼示例>>Java>>正文


Java Spinner.setSelection方法代碼示例

本文整理匯總了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);
    }

}
 
開發者ID:eyeRS,項目名稱:eyeRS,代碼行數:24,代碼來源:SetPINActivity.java

示例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);
}
 
開發者ID:masterjc,項目名稱:bluewatcher,代碼行數:25,代碼來源:ControlModeEditorActivity.java

示例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)));
}
 
開發者ID:axlecho,項目名稱:tuxguitar,代碼行數:8,代碼來源:TGTrackChannelDialog.java

示例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;
        }
    }
}
 
開發者ID:CMPUT301F17T15,項目名稱:CIA,代碼行數:23,代碼來源:HabitViewActivity.java

示例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);
}
 
開發者ID:ZetsPsych,項目名稱:kibou-game-library,代碼行數:27,代碼來源:SettingsActivity.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:ColorsActivity.java

示例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);
}
 
開發者ID:pili-engineering,項目名稱:PLDroidShortVideo,代碼行數:35,代碼來源:MainActivity.java

示例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));
}
 
開發者ID:universum-studios,項目名稱:android_ui,代碼行數:37,代碼來源:MenusFragment.java

示例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));
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:41,代碼來源:EditIssueActivity.java

示例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));
}
 
開發者ID:olgamiller,項目名稱:SSTVEncoder2,代碼行數:9,代碼來源:EditTextActivity.java

示例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)));
	}
}
 
開發者ID:axlecho,項目名稱:tuxguitar,代碼行數:13,代碼來源:TGHarmonicDialog.java

示例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)));
}
 
開發者ID:axlecho,項目名稱:tuxguitar,代碼行數:8,代碼來源:TGMeasureAddDialog.java

示例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);
}
 
開發者ID:graviton57,項目名稱:DOUSalaries,代碼行數:13,代碼來源:SalaryWidgetFragment.java

示例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);
}
 
開發者ID:digital-voting-pass,項目名稱:polling-station-app,代碼行數:32,代碼來源:ManualInputActivity.java

示例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);
}
 
開發者ID:jonasjuffinger,項目名稱:TimeLapse,代碼行數:61,代碼來源:SettingsActivity.java


注:本文中的android.widget.Spinner.setSelection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。