Java Code Examples for android.widget.Spinner#setAdapter()

The following examples show how to use android.widget.Spinner#setAdapter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From android-apps with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	spnView3 = (Spinner) findViewById(R.id.spnView3);
	
	ArrayList<String> aList = new ArrayList<String>();
	aList.add("--Select--");
	aList.add("Md. Shahadat Sarker");
	aList.add("Developer");
	aList.add("ErrrorPoint");
	
	spnView3.setAdapter(new SpinnerAdapter(this, R.layout.spinner_row, aList, aList));
	
	Toast.makeText(this, "Selected: " + spnView3.getSelectedItem(), 500).show();
	
}
 
Example 2
Source File: MainActivity.java    From speech-android-sdk with Apache License 2.0 6 votes vote down vote up
public void addItemsOnSpinnerVoices() {

            Spinner spinner = (Spinner)mView.findViewById(R.id.spinnerVoices);
            int iIndexDefault = 0;

            JSONObject obj = jsonVoices;
            ItemVoice [] items = null;
            try {
                JSONArray voices = obj.getJSONArray("voices");
                items = new ItemVoice[voices.length()];
                for (int i = 0; i < voices.length(); ++i) {
                    items[i] = new ItemVoice(voices.getJSONObject(i));
                    if (voices.getJSONObject(i).getString("name").equals(getString(R.string.voiceDefault))) {
                        iIndexDefault = i;
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (items != null) {
		        ArrayAdapter<ItemVoice> spinnerArrayAdapter = new ArrayAdapter<ItemVoice>(getActivity(), android.R.layout.simple_spinner_item, items);
		        spinner.setAdapter(spinnerArrayAdapter);
		        spinner.setSelection(iIndexDefault);
            }
        }
 
Example 3
Source File: SearchActivity.java    From Blood-Donation with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    spinner = (Spinner) findViewById(R.id.spinner);
    spinner2 = (Spinner) findViewById(R.id.spinner2);
   // WebView browser = (WebView) findViewById(R.id.webview);


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(SearchActivity.this,
            android.R.layout.simple_spinner_item, paths);
    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(SearchActivity.this,
            android.R.layout.simple_spinner_item, types);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);
    spinner2.setAdapter(adapter2);
    spinner2.setOnItemSelectedListener(this);
   /* browser.setWebViewClient(new WebViewClient() {
                                 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                                     handler.proceed();
                                 }
                             });
    browser.loadUrl("https://google-developers.appspot.com/maps/documentation/javascript/examples/full/map-simple");*/
}
 
Example 4
Source File: MainActivity.java    From HintSpinnerAdapter with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Spinner ordinarySpinner = (Spinner) findViewById(R.id.ordinarySpinner);
    Spinner hintSpinner = (Spinner) findViewById(R.id.hintSpinner);

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.color, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    ordinarySpinner.setPrompt("Select your favorite color!");
    ordinarySpinner.setAdapter(adapter);

    hintSpinner.setAdapter(new HintSpinnerAdapter(
                    adapter, R.layout.hint_row_item, this));
}
 
Example 5
Source File: AccountUtils.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up account spinner.
 * 
 * @param fragmentActivity tyhe fragment activity
 * @param spinner the spinner
 * @param accounts the accounts
 */
public static void setupAccountSpinner(
    FragmentActivity fragmentActivity, Spinner spinner, Account[] accounts) {
  if (accounts.length > 1) {
    String shareTrackAccount = PreferencesUtils.getString(fragmentActivity,
        R.string.share_track_account_key, PreferencesUtils.SHARE_TRACK_ACCOUNT_DEFAULT);
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
        fragmentActivity, R.layout.account_spinner_item);
    int selection = 0;
    for (int i = 0; i < accounts.length; i++) {
      String name = accounts[i].name;
      adapter.add(name);
      if (name.equals(shareTrackAccount)) {
        selection = i;
      }
    }
    adapter.setDropDownViewResource(R.layout.account_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(selection);
  }
}
 
Example 6
Source File: ForumSearchActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Forums");
   	
	Spinner sortSpin = (Spinner) findViewById(R.id.sortSpin);
	ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.simple_spinner_dropdown_item, new String[]{
       			"connects",
       			"connects today",
       			"connects this week",
       			"connects this month",
       			"last connect",
       			"name",
       			"date",
       			"posts",
           		"thumbs up",
           		"thumbs down",
           		"stars"
       });
	sortSpin.setAdapter(adapter);
}
 
Example 7
Source File: TreeSync.java    From HtmlView2 with Apache License 2.0 6 votes vote down vote up
static void syncSelect(Spinner spinner, Hv2DomElement element) {
  ArrayAdapter<String> options = new ArrayAdapter<String>(spinner.getContext(),
      android.R.layout.simple_spinner_dropdown_item);
  spinner.setAdapter(options);

  Hv2DomElement child = element.getFirstElementChild();
  while (child != null) {
    if (child.getLocalName().equals("option")) {
      boolean selected = child.getAttribute("selected") != null;
      String content = child.getTextContent();
      options.add(content);
      if (child.getAttribute("selected") != null) {
        spinner.setSelection(options.getCount() - 1);
      }
      child = child.getNextElementSibling();
    }
  }
}
 
Example 8
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create the spinner.
    Spinner spinner = findViewById(R.id.label_spinner);
    if (spinner != null) {
        spinner.setOnItemSelectedListener(this);
    }

    // Create ArrayAdapter using the string array and default
    // spinner layout.
    ArrayAdapter<CharSequence> adapter =
            ArrayAdapter.createFromResource(
                    this, R.array.labels_array,
                    android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears.
    adapter.setDropDownViewResource
            (android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    if (spinner != null) {
        spinner.setAdapter(adapter);
    }
}
 
Example 9
Source File: CreatePoiFragment.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
private void setupView() {
    createPoiFeature = (TextView) getActivity().findViewById(R.id.createPoiFeature);
    createPoiFeature.setOnClickListener(clickListener);
    createName = (EditText) getActivity().findViewById(R.id.createName);
    createStreet = (EditText) getActivity().findViewById(R.id.createStreet);
    createHouseNumber = (EditText) getActivity().findViewById(R.id.createHouseNumber);
    createPostCode = (EditText) getActivity().findViewById(R.id.createPostCode);
    createCity = (EditText) getActivity().findViewById(R.id.createCity);
    createPhone = (EditText) getActivity().findViewById(R.id.createPhone);
    createWebsite = (EditText) getActivity().findViewById(R.id.createWebsite);
    createEmail = (EditText) getActivity().findViewById(R.id.createEmail);
    createInternetContainer = (LinearLayout) getActivity().findViewById(R.id.createInternetContainer);
    createInternet = (Spinner) getActivity().findViewById(R.id.createInternet);
    dropdownItems = new String[]{"", getString(R.string.yes), getString(R.string.no), getString(R.string.wifi), getString(R.string.wired), getString(R.string.wlan)};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, dropdownItems);
    createInternet.setAdapter(adapter);

    TextView osmCopyright = (TextView) getActivity().findViewById(R.id.osmCopyrightCreatePoi);
    osmCopyright.setText(Html.fromHtml(getString(R.string.osm_copyright)));
    toolbar = (Toolbar) getActivity().findViewById(R.id.createPoiToolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener()

    {
        @Override
        public void onClick(View v) {
            closeFragment();
        }
    });
    toolbar.inflateMenu(R.menu.update_poi);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (!allFieldsValid()) return true;
            createPoi();
            return true;
        }
    });
}
 
Example 10
Source File: main_card.java    From octodroid with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void onPostExecute(String[][] strings) {
    try {
        if (strings[0][0].contains("null")) {
            final Button right = (Button) rootView.findViewById(R.id.buttonConDis);
            right.setText("Connect");
            right.setEnabled(false);
            return;
        }
    }catch (Exception e){

    }
    ArrayList<String> spinnerArray = new ArrayList<String>();
    for (String i : strings[0]){
        spinnerArray.add(i.replace("\\/", "/"));
    }
    ArrayList<String> spinnerArray2 = new ArrayList<String>();
    for (String i2 : strings[1]){
        spinnerArray2.add(i2);
    }
    LinearLayout layout = new LinearLayout(rootView.getContext());
    final Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_dropdown_item, spinnerArray);
    spinner.setAdapter(spinnerArrayAdapter);
    spinner.setEnabled(true);

    final Spinner spinner2 = (Spinner) rootView.findViewById(R.id.spinner2);
    ArrayAdapter<String> spinnerArrayAdapter2 = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_dropdown_item, spinnerArray2);
    spinner2.setAdapter(spinnerArrayAdapter2);
    spinner2.setEnabled(true);


}
 
Example 11
Source File: Controls1.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.controls_1);

    Button disabledButton = (Button) findViewById(R.id.button_disabled);
    disabledButton.setEnabled(false);

    Spinner s1 = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, mStrings);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s1.setAdapter(adapter);
}
 
Example 12
Source File: TwoFactorPreferenceFragment.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
private boolean onLimitsPreferenceClicked(final Preference preference) {
    final View v = UI.inflateDialog(getActivity(), R.layout.dialog_set_limits);
    final Spinner currencySpinner = UI.find(v, R.id.set_limits_currency);
    final EditText amountEdit = UI.find(v, R.id.set_limits_amount);

    final String[] currencies;
    if (mService.isElements())
        currencies = new String[]{mService.getAssetSymbol()};
    else if (!mService.hasFiatRate())
        currencies = new String[]{"BTC"};
    else
        currencies = new String[]{"BTC", mService.getFiatCurrency()};

    final ArrayAdapter<String> adapter;
    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, currencies);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    currencySpinner.setAdapter(adapter);
    if (currencies.length > 1 && mService.getSpendingLimits().getBool("is_fiat"))
        currencySpinner.setSelection(1);

    final MaterialDialog dialog;
    dialog = UI.popup(getActivity(), R.string.twoFacLimitTitle)
               .customView(v, true)
               .onPositive(new MaterialDialog.SingleButtonCallback() {
                   @Override
                   public void onClick(final MaterialDialog dlg, final DialogAction which) {
                       try {
                           final String currency = currencySpinner.getSelectedItem().toString();
                           final String amount = UI.getText(amountEdit);
                           final boolean isFiat = !currency.equals(currencies[0]);
                           onNewLimitsSelected(TextUtils.isEmpty(amount) ? "0" : amount, isFiat);
                       } catch (final Exception e) {
                           UI.toast(getActivity(), "Error setting limits", Toast.LENGTH_LONG);
                       }
                   }
               }).build();
    UI.showDialog(dialog);
    return false;
}
 
Example 13
Source File: AlbumActivity.java    From medialibrary with Apache License 2.0 5 votes vote down vote up
private void setupSpinner() {
    Spinner spinner = findViewById(R.id.spinner);
    spinner.setOnItemSelectedListener(mMainItemSelected);

    List<String> categories = new ArrayList<>();

    categories.add("All");
    categories.add("Photos");
    categories.add("Videos");


    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);

    Spinner spinnerFilter = findViewById(R.id.spinnerFilter);
    spinnerFilter.setOnItemSelectedListener(mFilterItemSelected);

    List<String> filter = new ArrayList<>();

    filter.add("CLUSTER BY ALBUM");
    filter.add("CLUSTER BY TIME");
    filter.add("CLUSTER BY LOCATION");
    filter.add("CLUSTER BY TAG");
    filter.add("CLUSTER BY SIZE");
    filter.add("CLUSTER BY FACE");


    ArrayAdapter<String> dataAdapterFilter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, filter);
    dataAdapterFilter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerFilter.setAdapter(dataAdapterFilter);

}
 
Example 14
Source File: ServerDialog.java    From an2linuxclient with GNU General Public License v3.0 5 votes vote down vote up
void initViewsDialogNew(View v) {
    ServerDatabaseHandler dbHandler = ServerDatabaseHandler.getInstance(getActivity());

    if (dbHandler.isThereAnyCertificatesInDatabase()){
        certificateSpinner = (Spinner) v.findViewById(R.id.certificateSpinner);
        List<CertificateSpinnerItem> spinnerList = dbHandler.getSpinnerList();
        spinnerList.add(0, new CertificateSpinnerItem(){
            @Override
            public String toString(){
                return getString(R.string.spinner_choose_certificate);
            }
        });
        pairingInfoTextView.setVisibility(View.GONE);
        initiatePairingButton.setText(R.string.dialog_pairing_button_text_or);
        ArrayAdapter<CertificateSpinnerItem> spinnerArrayAdapter = new ArrayAdapter<>(
                getActivity().getApplicationContext(),
                R.layout.dialog_certificate_spinner_textview,
                spinnerList);
        spinnerArrayAdapter.setDropDownViewResource(R.layout.dialog_certificate_spinner_dropdown_textview);
        certificateSpinner.setAdapter(spinnerArrayAdapter);
        certificateSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);
        certificateSpinner.setOnTouchListener(this);
        certificateSpinner.setOnItemSelectedListener(this);
    } else {
        v.findViewById(R.id.certificateSpinner).setVisibility(View.GONE);
    }

    v.findViewById(R.id.deleteServerBtn).setVisibility(View.INVISIBLE);

    dbHandler.close();
}
 
Example 15
Source File: SubsonicActivity.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
private void createCustomActionBarView() {
    actionBarSpinner = (Spinner) getLayoutInflater().inflate(R.layout.actionbar_spinner, null);
    if ((this instanceof SubsonicFragmentActivity || this instanceof SettingsActivity) && ThemeUtil.getThemeRes(this) != R.style.Theme_Audinaut_Light) {
        actionBarSpinner.setBackground(DrawableTint.getTintedDrawableFromColor(this));
    }
    spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    actionBarSpinner.setOnItemSelectedListener(this);
    actionBarSpinner.setAdapter(spinnerAdapter);

    getSupportActionBar().setCustomView(actionBarSpinner);
}
 
Example 16
Source File: ASBTalismanDialogFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private Spinner initializeSlotsSpinner(View view) {
    Spinner spinner = (Spinner) view.findViewById(R.id.talisman_slots_spinner);
    spinner.setAdapter(ArrayAdapter.createFromResource(getActivity(), R.array.slot_values,
                                                       android.R.layout.simple_spinner_dropdown_item));
    ((ArrayAdapter) spinner.getAdapter()).setDropDownViewResource(R.layout.view_spinner_dropdown_item);

    return spinner;
}
 
Example 17
Source File: HoroscopeAPIActivity.java    From stynico with MIT License 5 votes vote down vote up
private void initSpinner(int start, int end, Spinner spinner)
   {
ArrayList<String> spinnerList = new ArrayList<String>();

for (int i = start; i < end + 1; i++)
{
    spinnerList.add(IntegerToString(i));
}

spinner.setAdapter(new ArrayAdapter<String>(this, R.layout.view_spinner, spinnerList));
   }
 
Example 18
Source File: WifiConfigCreationDialog.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();

    View dialogView = inflater.inflate(R.layout.wifi_config_dialog, null);
    mPasswordView = dialogView.findViewById(R.id.password_layout);
    mSsidText = (EditText) dialogView.findViewById(R.id.ssid);
    mSsidText.addTextChangedListener(this);
    mPasswordText = (EditText) dialogView.findViewById(R.id.password);
    mPasswordText.addTextChangedListener(this);

    mSecurityChoicesSpinner = (Spinner) dialogView.findViewById(R.id.security);
    mSecurityChoicesSpinner.setOnItemSelectedListener(this);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.wifi_security_choices, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSecurityChoicesSpinner.setAdapter(adapter);
    initialize();

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.add_network)
            .setView(dialogView)
            // Listener for save button will be set in onStart().
            .setPositiveButton(R.string.wifi_save, null)
            .setNegativeButton(R.string.wifi_cancel, null);

    return builder.create();
}
 
Example 19
Source File: ViewMatchersTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
@Test
public void withSpinnerTextResourceId() {
  Spinner spinner = new Spinner(this.context);
  List<String> values = Lists.newArrayList();
  values.add(this.context.getString(R.string.something));
  values.add(this.context.getString(R.string.other_string));
  ArrayAdapter<String> adapter =
      new ArrayAdapter<String>(this.context, android.R.layout.simple_spinner_item, values);
  spinner.setAdapter(adapter);
  spinner.setSelection(0);
  assertTrue(withSpinnerText(R.string.something).matches(spinner));
  assertFalse(withSpinnerText(R.string.other_string).matches(spinner));
}
 
Example 20
Source File: SettingsActivity.java    From iqra-android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    android.support.v7.app.ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setElevation(0);
        ab.setTitle(getResources().getString(R.string.settings_title));
    }

    // Obtain the shared Tracker instance.
    AnalyticsApplication application = (AnalyticsApplication) getApplication();
    mTracker = application.getDefaultTracker();

    context = this;
    prefs = this.getSharedPreferences("com.mmmoussa.iqra", MODE_PRIVATE);

    translationShortForms = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.translation_code)));

    String currentTranslation = prefs.getString("translation", "en-hilali");
    int currentTranslationIndex = translationShortForms.indexOf(currentTranslation);
    if (currentTranslationIndex == -1) {
        // This should never run but just in case...
        currentTranslationIndex = 1;
    }

    translationSpinner = (Spinner) findViewById(R.id.translationSpinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.translation_spinner_item, getResources().getStringArray(R.array.translation_array));
    translationSpinner.setAdapter(adapter);
    translationSpinner.setSelection(currentTranslationIndex);

    Button saveButton = (Button) findViewById(R.id.saveButton);
    saveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            prefs.edit().putString("translation", translationShortForms.get(translationSpinner.getSelectedItemPosition())).apply();
            finish();
        }
    });
}