android.widget.Spinner.getSelectedItem()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(523)

本文整理了Java中android.widget.Spinner.getSelectedItem()方法的一些代码示例,展示了Spinner.getSelectedItem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spinner.getSelectedItem()方法的具体详情如下:
包路径:android.widget.Spinner
类名称:Spinner
方法名:getSelectedItem

Spinner.getSelectedItem介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();

代码示例来源:origin: greenrobot/EventBus

public void startClick(View v) {
  TestParams params = new TestParams();
  Spinner spinnerThread = findViewById(R.id.spinnerThread);
  String threadModeStr = spinnerThread.getSelectedItem().toString();
  ThreadMode threadMode = ThreadMode.valueOf(threadModeStr);
  params.setThreadMode(threadMode);
  params.setEventInheritance(((CheckBox) findViewById(R.id.checkBoxEventBusEventHierarchy)).isChecked());
  params.setIgnoreGeneratedIndex(((CheckBox) findViewById(R.id.checkBoxEventBusIgnoreGeneratedIndex)).isChecked());
  EditText editTextEvent = findViewById(R.id.editTextEvent);
  params.setEventCount(Integer.parseInt(editTextEvent.getText().toString()));
  EditText editTextSubscriber = findViewById(R.id.editTextSubscribe);
  params.setSubscriberCount(Integer.parseInt(editTextSubscriber.getText().toString()));
  Spinner spinnerTestToRun = findViewById(R.id.spinnerTestToRun);
  int testPos = spinnerTestToRun.getSelectedItemPosition();
  params.setTestNumber(testPos + 1);
  ArrayList<Class<? extends Test>> testClasses = initTestClasses(testPos);
  params.setTestClasses(testClasses);
  Intent intent = new Intent();
  intent.setClass(this, TestRunnerActivity.class);
  intent.putExtra("params", params);
  startActivity(intent);
}

代码示例来源:origin: stackoverflow.com

Spinner mySpinner=(Spinner) findViewById(R.id.your_spinner);
String text = mySpinner.getSelectedItem().toString();

代码示例来源:origin: k9mail/k-9

private ConnectionSecurity getSelectedSecurity() {
    ConnectionSecurityHolder holder = (ConnectionSecurityHolder) mSecurityTypeView.getSelectedItem();
    return holder.connectionSecurity;
  }
}

代码示例来源:origin: k9mail/k-9

private ConnectionSecurity getSelectedSecurity() {
    ConnectionSecurityHolder holder = (ConnectionSecurityHolder) mSecurityTypeView.getSelectedItem();
    return holder.connectionSecurity;
  }
}

代码示例来源:origin: k9mail/k-9

private AuthType getSelectedAuthType() {
  AuthTypeHolder holder = (AuthTypeHolder) mAuthTypeView.getSelectedItem();
  return holder.authType;
}

代码示例来源:origin: k9mail/k-9

private AuthType getSelectedAuthType() {
  AuthTypeHolder holder = (AuthTypeHolder) mAuthTypeView.getSelectedItem();
  return holder.authType;
}

代码示例来源:origin: stackoverflow.com

Spinner spinner = (Spinner) myView.findViewById(R.id.theState);
String selected = ((States)spinner.getSelectedItem()).name();

代码示例来源:origin: stackoverflow.com

final Spinner sp3= (Spinner) findViewById(R.id.spinner3);
ArrayAdapter<CharSequence> adp3=ArrayAdapter.createFromResource(this,
            R.array.str2, android.R.layout.simple_list_item_1);

    adp3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp3.setAdapter(adp3);
sp3.setOnItemSelectedListener(new OnItemSelectedListener()
    {

       @Override
       public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
       // TODO Auto-generated method stub
     String ss=sp3.getSelectedItem().toString();
                        Toast.makeText(getBaseContext(),ss , Toast.LENGTH_SHORT).show();

     }

     @Override
   public void onNothingSelected(AdapterView<?> arg0) {
      // TODO Auto-generated method stub

      }

    });

代码示例来源:origin: ankidroid/Anki-Android

private String computeAddressOfTranslationPage() {
  // Service name has to be replaced from the language lister.
  String address = "http://dict.tu-chemnitz.de/dings.cgi?lang=en&service=SERVICE&opterrors=0&optpro=0&query=Welt";
  String strFrom = mSpinnerFrom.getSelectedItem().toString();
  String langCodeFrom = mLanguageLister.getCodeFor(strFrom);
  String query;
  try {
    query = URLEncoder.encode(mSource, "utf-8");
  } catch (UnsupportedEncodingException e) {
    query = mSource.replace(" ", "%20");
  }
  address = address.replaceAll("SERVICE", langCodeFrom).replaceAll("Welt", query);
  return address;
}

代码示例来源:origin: graphhopper/graphhopper

@Override
  public void onClick(View v) {
    Object o = spinner.getSelectedItem();
    if (o != null && o.toString().length() > 0 && !nameToFullName.isEmpty()) {
      String area = o.toString();
      myListener.onSelect(area, nameToFullName.get(area));
    } else {
      myListener.onSelect(null, null);
    }
  }
});

代码示例来源:origin: ankidroid/Anki-Android

private String computeAddress() {
  String address = "http://glosbe.com/gapi/translate?from=FROMLANG&dest=TOLANG&format=json&phrase=SOURCE&pretty=true";
  String strFrom = mSpinnerFrom.getSelectedItem().toString();
  // Conversion to iso, lister created before.
  String langCodeFrom = mLanguageLister.getCodeFor(strFrom);
  String strTo = mSpinnerTo.getSelectedItem().toString();
  mLangCodeTo = mLanguageLister.getCodeFor(strTo);
  String query;
  try {
    query = URLEncoder.encode(mSource, "utf-8");
  } catch (UnsupportedEncodingException e) {
    query = mSource.replace(" ", "%20");
  }
  address = address.replaceAll("FROMLANG", langCodeFrom).replaceAll("TOLANG", mLangCodeTo)
      .replaceAll("SOURCE", query);
  return address;
}

代码示例来源:origin: commonsguy/cw-omnibus

public void sendTheMessage(View v) {
  Cursor c=(Cursor)contacts.getSelectedItem();
  
  if (means.getCheckedRadioButtonId()==R.id.client) {
   Intent sms=new Intent(Intent.ACTION_SENDTO,
              Uri.parse("smsto:"+c.getString(2)));
   
   sms.putExtra("sms_body", msg.getText().toString());
   
   startActivity(sms);
  }
  else {
   SmsManager
    .getDefault()
    .sendTextMessage(c.getString(2), null,
             msg.getText().toString(),
             null, null);
  }
 }
}

代码示例来源:origin: card-io/card.io-Android-SDK

public void onScan(View pressed) {
  Intent intent = new Intent(this, CardIOActivity.class)
      .putExtra(CardIOActivity.EXTRA_NO_CAMERA, mManualToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, mEnableExpiryToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_SCAN_EXPIRY, mScanExpiryToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, mCvvToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, mPostalCodeToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY, mPostalCodeNumericOnlyToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_REQUIRE_CARDHOLDER_NAME, mCardholderNameToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, mSuppressManualToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_USE_CARDIO_LOGO, mUseCardIOLogoToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_LANGUAGE_OR_LOCALE, (String) mLanguageSpinner.getSelectedItem())
      .putExtra(CardIOActivity.EXTRA_USE_PAYPAL_ACTIONBAR_ICON, mShowPayPalActionBarIconToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_KEEP_APPLICATION_THEME, mKeepApplicationThemeToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_GUIDE_COLOR, Color.GREEN)
      .putExtra(CardIOActivity.EXTRA_SUPPRESS_CONFIRMATION, mSuppressConfirmationToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_SUPPRESS_SCAN, mSuppressScanToggle.isChecked())
      .putExtra(CardIOActivity.EXTRA_RETURN_CARD_IMAGE, true);
  try {
    int unblurDigits = Integer.parseInt(mUnblurEdit.getText().toString());
    intent.putExtra(CardIOActivity.EXTRA_UNBLUR_DIGITS, unblurDigits);
  } catch(NumberFormatException ignored) {}
  startActivityForResult(intent, REQUEST_SCAN);
}

代码示例来源: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: Piasy/BigImageViewer

private void showImage() {
    String imageSize = (String) mImageSize.getSelectedItem();
    if (TextUtils.equals(imageSize, getString(R.string.size_small))) {
      mBigImageView.showImage(mSmallImage);
    } else if (TextUtils.equals(imageSize, getString(R.string.size_medium))) {
      mBigImageView.showImage(mMediumImage);
    } else if (TextUtils.equals(imageSize, getString(R.string.size_big))) {
      mBigImageView.showImage(mBigImage);
    }
  }
}

代码示例来源:origin: Piasy/BigImageViewer

private void setScaleType() {
  String scaleType = (String) mScaleType.getSelectedItem();
  if (TextUtils.equals(scaleType, getString(R.string.scale_center_crop))) {
    mBigImageView.setInitScaleType(BigImageView.INIT_SCALE_TYPE_CENTER_CROP);
  } else if (TextUtils.equals(scaleType, getString(R.string.scale_center_inside))) {
    mBigImageView.setInitScaleType(BigImageView.INIT_SCALE_TYPE_CENTER_INSIDE);
  } else if (TextUtils.equals(scaleType, getString(R.string.scale_custom))) {
    mBigImageView.setInitScaleType(BigImageView.INIT_SCALE_TYPE_CUSTOM);
  } else if (TextUtils.equals(scaleType, getString(R.string.scale_start))) {
    mBigImageView.setInitScaleType(BigImageView.INIT_SCALE_TYPE_START);
  }
}

代码示例来源: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();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getSelectedItemShouldReturnNull_NoAdapterSet(){
 assertThat(spinner.getSelectedItem()).isNull();
}

代码示例来源:origin: k9mail/k-9

private void onDone() {
  mAccount.setDescription(mAccount.getEmail());
  mAccount.setNotifyNewMail(mNotifyView.isChecked());
  mAccount.setNotifySync(mNotifySyncView.isChecked());
  mAccount.setAutomaticCheckIntervalMinutes((Integer)((SpinnerOption)mCheckFrequencyView
      .getSelectedItem()).value);
  mAccount.setDisplayCount((Integer)((SpinnerOption)mDisplayCountView
                    .getSelectedItem()).value);
  if (mPushEnable.isChecked()) {
    mAccount.setFolderPushMode(Account.FolderMode.FIRST_CLASS);
  } else {
    mAccount.setFolderPushMode(Account.FolderMode.NONE);
  }
  Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount);
  if (mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()) ||
      getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false)) {
    Preferences.getPreferences(this).setDefaultAccount(mAccount);
  }
  Core.setServicesEnabled(this);
  AccountSetupNames.actionSetNames(this, mAccount);
  finish();
}

相关文章