List of usage examples for android.widget ArrayAdapter setDropDownViewResource
public void setDropDownViewResource(@LayoutRes int resource)
Sets the layout resource to create the drop down views.
From source file:br.com.bioscada.apps.biotracks.fragments.ExportDialogFragment.java
private void setupExportTypeOptions(FragmentActivity fragmentActivity) { boolean hideDrive = getArguments().getBoolean(KEY_HIDE_DRIVE); ExportType exportType = ExportType.valueOf(PreferencesUtils.getString(fragmentActivity, R.string.export_type_key, PreferencesUtils.EXPORT_TYPE_DEFAULT)); if (hideDrive && exportType == ExportType.GOOGLE_DRIVE) { exportType = ExportType.GOOGLE_MAPS; }//from ww w . j a va2 s.co m exportTypeOptionsList = new ArrayList<ExportDialogFragment.ExportType>(); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item); if (accounts.length > 0) { if (!hideDrive) { exportTypeOptionsList.add(ExportType.GOOGLE_DRIVE); } exportTypeOptionsList.add(ExportType.GOOGLE_MAPS); exportTypeOptionsList.add(ExportType.GOOGLE_FUSION_TABLES); exportTypeOptionsList.add(ExportType.GOOGLE_SPREADSHEET); } exportTypeOptionsList.add(ExportType.EXTERNAL_STORAGE); int selection = 0; for (int i = 0; i < exportTypeOptionsList.size(); i++) { ExportType type = exportTypeOptionsList.get(i); adapter.add(getString(type.resId)); if (type == exportType) { selection = i; } } adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); exportTypeOptions.setAdapter(adapter); exportTypeOptions.setSelection(selection); exportTypeOptions.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ExportType type = exportTypeOptionsList.get(position); exportGoogleMapsOptions.setVisibility(type == ExportType.GOOGLE_MAPS ? View.VISIBLE : View.GONE); exportGoogleFusionTablesOptions .setVisibility(type == ExportType.GOOGLE_FUSION_TABLES ? View.VISIBLE : View.GONE); exportExternalStorageOptions .setVisibility(type == ExportType.EXTERNAL_STORAGE ? View.VISIBLE : View.GONE); accountSpinner.setVisibility( accounts.length > 1 && type != ExportType.EXTERNAL_STORAGE ? View.VISIBLE : View.GONE); } @Override public void onNothingSelected(AdapterView<?> parent) { // Safely ignore } }); }
From source file:nf.frex.android.FrexActivity.java
private void prepareDecorationsDialog(final Dialog dialog) { final Registry<DistanceFunction> distanceFunctions = Registries.distanceFunctions; int checkedIndex = distanceFunctions.getIndex(view.getDistanceFunctionId()); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, distanceFunctions.getIds()); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner distanceFunctionSpinner = (Spinner) dialog.findViewById(R.id.distance_function_spinner); distanceFunctionSpinner.setAdapter(arrayAdapter); distanceFunctionSpinner.setSelection(checkedIndex, false); final SeekBarConfigurer dilationSeekBarConfigurer = SeekBarConfigurer.create( (SeekBar) dialog.findViewById(R.id.dilation_seek_bar), -3.0, 1.0, true, view.getDistanceDilation()); final SeekBarConfigurer translateXSeekBarConfigurer = SeekBarConfigurer.create( (SeekBar) dialog.findViewById(R.id.transl_x_seek_bar), -2.5, 2.5, false, view.getDistanceTranslateX()); final SeekBarConfigurer translateYSeekBarConfigurer = SeekBarConfigurer.create( (SeekBar) dialog.findViewById(R.id.transl_y_seek_bar), -2.5, 2.5, false, view.getDistanceTranslateY()); final CheckBox turbulenceCheckBox = (CheckBox) dialog.findViewById(R.id.turbulence); turbulenceCheckBox.setChecked(view.getGeneratorConfig().isTurbulenceEnabled()); final SeekBarConfigurer turbIntensSeekBarConfigurer = SeekBarConfigurer.create( (SeekBar) dialog.findViewById(R.id.turb_intens_seek_bar), -1.0, 1.0, true, view.getGeneratorConfig().getTurbulenceIntensity()); final SeekBarConfigurer turbScaleSeekBarConfigurer = SeekBarConfigurer.create( (SeekBar) dialog.findViewById(R.id.turb_scale_seek_bar), -1.0, 1.0, true, view.getGeneratorConfig().getTurbulenceScale()); Button randomButton = (Button) dialog.findViewById(R.id.random_button); randomButton.setOnClickListener(new View.OnClickListener() { @Override// w w w . j av a 2s. c o m public void onClick(View v) { distanceFunctionSpinner.setSelection((int) (Math.random() * distanceFunctions.getSize())); dilationSeekBarConfigurer.setRandomValue(); translateXSeekBarConfigurer.setRandomValue(); translateYSeekBarConfigurer.setRandomValue(); if (Math.random() < 0.5) { turbIntensSeekBarConfigurer.setRandomValue(); turbScaleSeekBarConfigurer.setRandomValue(); } } }); Button okButton = (Button) dialog.findViewById(R.id.ok_button); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int index = distanceFunctionSpinner.getSelectedItemPosition(); dialog.dismiss(); view.setDecoratedFractal(true); view.setDistanceFunctionId(distanceFunctions.getId(index)); view.setDistanceDilation(dilationSeekBarConfigurer.getValue()); view.setDistanceTranslateX(translateXSeekBarConfigurer.getValue()); view.setDistanceTranslateY(translateYSeekBarConfigurer.getValue()); view.getGeneratorConfig().setTurbulenceEnabled(turbulenceCheckBox.isChecked()); view.getGeneratorConfig().setTurbulenceIntensity(turbIntensSeekBarConfigurer.getValue()); view.getGeneratorConfig().setTurbulenceScale(turbScaleSeekBarConfigurer.getValue()); view.recomputeAll(); } }); Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }
From source file:com.hangulo.powercontact.ContactsListFragment.java
void setDistanceSpinnerAdapter() { // title must be changed by locale / ?? ? ?? ? . final int num_array_pref_range_distance_titles; final int num_array_pref_range_distance_values; Log.v(LOG_TAG, "setDistanceSpinnerAdapter distance"); // set mile or meter by locale ?? ? ? ? . if (mCallback.getPowerContactSettings().getRealDistanceUnits() == Constants.DISTANCE_UNITS_METER) { num_array_pref_range_distance_titles = R.array.pref_range_distance_titles_meter; num_array_pref_range_distance_values = R.array.pref_range_distance_values_meter; } else {/* w w w. j av a2s. co m*/ num_array_pref_range_distance_titles = R.array.pref_range_distance_titles_mile; num_array_pref_range_distance_values = R.array.pref_range_distance_values_mile; } ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), num_array_pref_range_distance_titles, android.R.layout.simple_spinner_item); // R.layout.spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerDistance.setAdapter(adapter); // mSpinnerDistance.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { double distance = setSpinnerDistanceChanged(position, num_array_pref_range_distance_values); // change distance // ?.. ?? .. Log.v(LOG_TAG, "mSpinnerDistance/listener : loader restart distace:" + distance + "time" + System.currentTimeMillis()); mCallback.restartMainLoader(distance); // restart main loader // ? .. ? ? ?. ? ? ?. } @Override public void onNothingSelected(AdapterView<?> parent) { } }); String[] strArray = getResources().getStringArray(num_array_pref_range_distance_values); Double distance = getDistance(); // ? . Log.v(LOG_TAG, "setDistanceSpinnerAdapter distance setSection" + distance); int i; for (i = 0; i < strArray.length; i++) if (Double.parseDouble(strArray[i]) == distance) { mSpinnerDistance.setSelection(i); // 2016.3.31 . // setSpinnerDistanceChanged(i, num_array_pref_range_distance_values); // change distance break; } adapter.notifyDataSetChanged(); // http://stackoverflow.com/questions/9443370/how-to-update-an-spinner-dynamically-in-android-correctly }
From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java
/** * Spinner??./* www. j a va 2s.co m*/ */ private void initSpinner() { ArrayAdapter<CharSequence> adapterHttpMethod = ArrayAdapter.createFromResource(this, R.array.http_methods, android.R.layout.simple_spinner_item); adapterHttpMethod.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ArrayAdapter<CharSequence> adapterProfile = ArrayAdapter.createFromResource(this, R.array.dconnect_profile_list, android.R.layout.simple_spinner_item); adapterProfile.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.string_empty, android.R.layout.simple_spinner_item); mHM = (Spinner) findViewById(R.id.reqMethod); mHM.setAdapter(adapterHttpMethod); mHM.setOnItemSelectedListener(this); mProf = (Spinner) findViewById(R.id.reqProfile); mProf.setAdapter(adapterProfile); mProf.setOnItemSelectedListener(this); mInter = (Spinner) findViewById(R.id.reqInterfaces); mInter.setOnItemSelectedListener(this); mInter.setAdapter(adapter); mAttrib = (Spinner) findViewById(R.id.reqAttribute); mAttrib.setOnItemSelectedListener(this); mAttrib.setAdapter(adapter); mDI = (Spinner) findViewById(R.id.reqDeviceid); mDI.setOnItemSelectedListener(this); mDI.setAdapter(adapter); }
From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java
@Override public void onItemSelected(final AdapterView<?> parent, final View v, final int position, final long pos) { int id = parent.getId(); Spinner spinner = (Spinner) parent;/*from w w w .j a v a2s . co m*/ if (id == R.id.reqProfile) { String profileName = spinner.getSelectedItem().toString(); if (!profileName.equals("")) { int resInterfacesId = getResources().getIdentifier(profileName + "_interface_list", "array", getPackageName()); ArrayAdapter<CharSequence> adapterInterfaces = ArrayAdapter.createFromResource(this, resInterfacesId, android.R.layout.simple_spinner_item); adapterInterfaces.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mInter.setAdapter(adapterInterfaces); int resAttributeId = getResources().getIdentifier(profileName + "_attrib_list", "array", getPackageName()); ArrayAdapter<CharSequence> adapterAttribute = ArrayAdapter.createFromResource(this, resAttributeId, android.R.layout.simple_spinner_item); adapterInterfaces.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mAttrib.setAdapter(adapterAttribute); } } }
From source file:net.olejon.mdapp.DiseasesAndTreatmentsSearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connected? if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 1); finish();// ww w .j av a 2 s . c om return; } // Intent final Intent intent = getIntent(); mSearchLanguage = intent.getStringExtra("language"); final String searchString = intent.getStringExtra("string"); // Layout setContentView(R.layout.activity_diseases_and_treatments_search); // Toolbar mToolbar = (Toolbar) findViewById(R.id.diseases_and_treatments_search_toolbar); mToolbar.setTitle(getString(R.string.diseases_and_treatments_search_search) + ": \"" + searchString + "\""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.diseases_and_treatments_search_toolbar_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Spinner mSpinner = (Spinner) findViewById(R.id.diseases_and_treatments_search_spinner); ArrayAdapter<CharSequence> arrayAdapter; if (mSearchLanguage.equals("")) { arrayAdapter = ArrayAdapter.createFromResource(mContext, R.array.diseases_and_treatments_search_spinner_items_english, R.layout.activity_diseases_and_treatments_search_spinner_header); } else { arrayAdapter = ArrayAdapter.createFromResource(mContext, R.array.diseases_and_treatments_search_spinner_items_norwegian, R.layout.activity_diseases_and_treatments_search_spinner_header); } arrayAdapter.setDropDownViewResource(R.layout.activity_diseases_and_treatments_search_spinner_item); mSpinner.setAdapter(arrayAdapter); mSpinner.setOnItemSelectedListener(this); // Refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById( R.id.diseases_and_treatments_search_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green, R.color.accent_purple, R.color.accent_orange); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { search(mSearchLanguage, searchString, false); } }); // Recycler view mRecyclerView = (RecyclerView) findViewById(R.id.diseases_and_treatments_search_cards); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(new DiseasesAndTreatmentsSearchAdapter(mContext, new JSONArray(), "")); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // Search search(mSearchLanguage, searchString, true); // Correct RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { final String correctSearchString = response.getString("correct"); if (!correctSearchString.equals("")) { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ContentValues contentValues = new ContentValues(); contentValues.put( DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING, correctSearchString); SQLiteDatabase sqLiteDatabase = new DiseasesAndTreatmentsSQLiteHelper( mContext).getWritableDatabase(); sqLiteDatabase.delete(DiseasesAndTreatmentsSQLiteHelper.TABLE, DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(searchString) + " COLLATE NOCASE", null); sqLiteDatabase.insert(DiseasesAndTreatmentsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); mToolbar.setTitle(getString( R.string.diseases_and_treatments_search_search) + ": \"" + correctSearchString + "\""); mProgressBar.setVisibility(View.VISIBLE); search(mSearchLanguage, correctSearchString, true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("DiseasesAndTreatments", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } }
From source file:com.pimp.companionforband.fragments.extras.ExtrasFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final SharedPreferences sharedPreferences = getContext().getSharedPreferences("MyPrefs", 0); final SharedPreferences.Editor editor = sharedPreferences.edit(); calculatorSwitch = (Switch) view.findViewById(R.id.calculator); calculatorSwitch.setOnClickListener(new View.OnClickListener() { @Override/* w w w . j av a 2s . c om*/ public void onClick(View v) { new calculatorTask().execute(); try { if (!doesTileExist(tileId)) addTile(); } catch (Exception e) { Log.e("CALC ADD", e.toString()); } } }); musicSwitch = (Switch) view.findViewById(R.id.music); musicSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new musicTask().execute(); } }); title = (EditText) view.findViewById(R.id.smstitle); body = (EditText) view.findViewById(R.id.smsbody); btnSend = (Button) view.findViewById(R.id.message_send); btnSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!title.getText().toString().equals("") || !body.getText().toString().equals("")) new smsTask().execute(); else Toast.makeText(getActivity(), getString(R.string.message_send_error), Toast.LENGTH_LONG).show(); } }); String[] haptic = { getString(R.string.notification_one), getString(R.string.notification_two), getString(R.string.notification_alarm), getString(R.string.notification_timer), getString(R.string.one_high), getString(R.string.two_high), getString(R.string.three_high), getString(R.string.ramp_up), getString(R.string.ramp_down) }; ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, haptic); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); hapticSpinner = ((Spinner) view.findViewById(R.id.haptic_spinner)); hapticSpinner.setAdapter(arrayAdapter); name = (EditText) view.findViewById(R.id.barcode_name); number = (EditText) view.findViewById(R.id.barcode_no); String[] type = { getString(R.string.barcode_type), "CODE39", "PDF417" }; String[] page = { getString(R.string.barcode_page), "1", "2", "3", "4", "5" }; arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, type); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); typeSpinner = ((Spinner) view.findViewById(R.id.type_spinner)); typeSpinner.setAdapter(arrayAdapter); arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, page); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); pageSpinner = ((Spinner) view.findViewById(R.id.page_spinner)); pageSpinner.setAdapter(arrayAdapter); pageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 1: name.setText(sharedPreferences.getString("name1", "Barcode 1")); number.setText(sharedPreferences.getString("no1", barcode39)); typeSpinner.setSelection(sharedPreferences.getInt("type1", 1)); break; case 2: name.setText(sharedPreferences.getString("name2", "Barcode 2")); number.setText(sharedPreferences.getString("no2", barcode417)); typeSpinner.setSelection(sharedPreferences.getInt("type2", 2)); break; case 3: name.setText(sharedPreferences.getString("name3", "Barcode 3")); number.setText(sharedPreferences.getString("no3", barcode39)); typeSpinner.setSelection(sharedPreferences.getInt("type3", 1)); break; case 4: name.setText(sharedPreferences.getString("name4", "Barcode 4")); number.setText(sharedPreferences.getString("no4", barcode417)); typeSpinner.setSelection(sharedPreferences.getInt("type4", 2)); break; case 5: name.setText(sharedPreferences.getString("name5", "Barcode 5")); number.setText(sharedPreferences.getString("no5", barcode39)); typeSpinner.setSelection(sharedPreferences.getInt("type5", 1)); break; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); btnBarcode = (Button) view.findViewById(R.id.barcode_send); btnBarcode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (name.getText().toString().equals("") || number.getText().toString().equals("")) Toast.makeText(getActivity(), getString(R.string.barcode_send_error_1), Toast.LENGTH_LONG) .show(); else if (typeSpinner.getSelectedItemPosition() == 0 || pageSpinner.getSelectedItemPosition() == 0) Toast.makeText(getActivity(), getString(R.string.barcode_send_error_2), Toast.LENGTH_LONG) .show(); else { int no = pageSpinner.getSelectedItemPosition(); editor.putString("name" + no, name.getText().toString()); editor.putString("no" + no, number.getText().toString()); editor.putInt("type" + no, typeSpinner.getSelectedItemPosition()); editor.apply(); new barcodeTask().execute(); } } }); btnHaptic = (Button) view.findViewById(R.id.haptic_send); btnHaptic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { VibrationType vibrationType = VibrationType.NOTIFICATION_ONE_TONE; switch (hapticSpinner.getSelectedItemPosition()) { case 0: vibrationType = VibrationType.NOTIFICATION_ONE_TONE; break; case 1: vibrationType = VibrationType.NOTIFICATION_TWO_TONE; break; case 2: vibrationType = VibrationType.NOTIFICATION_ALARM; break; case 3: vibrationType = VibrationType.NOTIFICATION_TIMER; break; case 4: vibrationType = VibrationType.ONE_TONE_HIGH; break; case 5: vibrationType = VibrationType.TWO_TONE_HIGH; break; case 6: vibrationType = VibrationType.THREE_TONE_HIGH; break; case 7: vibrationType = VibrationType.RAMP_UP; break; case 8: vibrationType = VibrationType.RAMP_DOWN; break; } try { MainActivity.client.getNotificationManager().vibrate(vibrationType).await(); } catch (BandException e) { BandUtils.handleBandException(e); } catch (Exception e) { MainActivity.appendToUI(e.getMessage(), "Style.ALERT"); } } }); cameraSwitch = (Switch) view.findViewById(R.id.camera); cameraSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new cameraTask().execute(); } }); flashlightSwitch = (Switch) view.findViewById(R.id.flashlight); flashlightSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new flashlightTask().execute(); } }); messageSwitch = (Switch) view.findViewById(R.id.message); messageSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { if (messageSwitch.isChecked()) addTile(); else new removeTask().execute(tileId); } catch (Exception e) { // } } }); barcodeSwitch = (Switch) view.findViewById(R.id.barcode); barcodeSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { if (barcodeSwitch.isChecked()) addBarcodeTile(); else new removeTask().execute(barcodeTileId); } catch (Exception e) { // } } }); pageSpinner.setSelection(1); new task().execute(); }
From source file:com.example.psumaps.MapView.java
public void addItemsOnSpinner() { spinner1 = (Spinner) findViewById(R.id.spinner1); spinner2 = (Spinner) findViewById(R.id.spinner2); List<String> list = new ArrayList<String>(); list.add("Art Building"); list.add("Academic and Student Recreation Center"); list.add("School of Business Administration"); list.add("The Broadway Housing Building"); list.add("Blackstone"); list.add("Corbett Building"); list.add("Cramer Hall"); list.add("Ondine Annex (Cinema)"); list.add("Collaborative Life Sciences Building"); list.add("Engineering Building"); list.add("School of Education"); list.add("East Hall"); list.add("Fourth Avenue Building"); list.add("Helen Gordon Child Development Center"); list.add("Harder House"); list.add("George C. Hoffmann Hall"); list.add("Harrison Street Building"); list.add("Joseph C. Blumel Residence Hall"); list.add("Koinonia House"); list.add("King Albert Building"); list.add("Lincoln Hall"); list.add("Market Center Building"); list.add("Branford Price Millar Library"); list.add("Montgomery Court"); list.add("Native American Student and Community Center"); list.add("North Greenhouse"); list.add("Neuberger Hall"); list.add("Ondine Residence"); list.add("Parkway Building"); list.add("University Pointe"); list.add("Parking Structure 1"); list.add("Parking Structure 2"); list.add("Parking Structure 3"); list.add("Peter W. Stott Center"); list.add("Research Greenhouse"); list.add("Science Building One"); list.add("Simon Benson House"); list.add("Science and Education Center"); list.add("Stephen E. Epler Hall"); list.add("South Greenhouse"); list.add("Shattuck Hall"); list.add("Smith Memorial Student Union"); list.add("Science Research and Teaching Center"); list.add("Stratford Building"); list.add("Saint Helens Building"); list.add("University Center Building"); list.add("University Honors Program"); list.add("University Place"); list.add("Urban Center"); list.add("University Services Building"); list.add("University Technology Services"); list.add("West Heating Plant"); list.add("XSB"); ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);//w ww . ja v a 2s. c o m dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(dataAdapter1); ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter(dataAdapter2); }
From source file:com.code.android.vibevault.SearchScreen.java
private void launchSettingsDialog() { final SeekBar seek; final Spinner sortSpin; final Spinner searchSpin; final TextView seekValue; // Make the settings dialog. AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("Search Settings"); View v = LayoutInflater.from(this).inflate(R.layout.scrollable_settings_dialog, null); ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { }/*from www.j av a2 s . c o m*/ }); // Grab all the GUI widgets. seek = (SeekBar) v.findViewById(R.id.NumResultsSeekBar); seek.setProgress(Integer.valueOf(VibeVault.db.getPref("numResults")) - 10); sortSpin = (Spinner) v.findViewById(R.id.SortSpinner); searchSpin = (Spinner) v.findViewById(R.id.SearchSpinner); seekValue = (TextView) v.findViewById(R.id.SeekBarValue); seekValue.setText(VibeVault.db.getPref("numResults")); // Set the seek bar to its current value, and set up a Listener. seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { seekValue.setText(String.valueOf(progress + 10)); VibeVault.db.updatePref("numResults", String.valueOf(progress + 10)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // Set up the spinner, and set up it's OnItemSelectedListener. ArrayAdapter<String> sortAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.sortChoices); sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sortSpin.setAdapter(sortAdapter); int sortPos = 1; String sortOrder = VibeVault.db.getPref("sortOrder"); for (int i = 0; i < VibeVault.sortChoices.length; i++) { if (VibeVault.sortChoices[i].equals(sortOrder)) sortPos = i; } sortSpin.setSelection(sortPos); sortSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.db.updatePref("sortOrder", VibeVault.sortChoices[selected]); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); ArrayAdapter<String> searchAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.searchChoices); searchAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); searchSpin.setAdapter(searchAdapter); int searchPos = 1; String searchOrder = VibeVault.searchPref; for (int i = 0; i < VibeVault.searchChoices.length; i++) { if (VibeVault.searchChoices[i].equals(searchOrder)) searchPos = i; } searchSpin.setSelection(searchPos); searchSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.searchPref = VibeVault.searchChoices[selected]; if (VibeVault.searchPref.equals("Artist") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Artists..."); } else if (VibeVault.searchPref.equals("Show/Artist Description") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Descriptions..."); } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // Show the settings screen. ad.setView(v); ad.show(); }
From source file:com.mifos.mifosxdroid.online.LoanAccountFragment.java
private void inflateLoanFundSpinner() { showProgress(true);/*from w w w . ja va2 s . c o m*/ App.apiManager.getLoansAccountTemplate(clientId, productId, new Callback<Response>() { @Override public void success(final Response result, Response response) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return; Log.d(LOG_TAG, ""); final List<LoanFund> loanFund = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> loanFundNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try { reader = new BufferedReader(new InputStreamReader(result.getBody().in())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("fundOptions")) { JSONArray loanFunds = obj.getJSONArray("fundOptions"); for (int i = 0; i < loanFunds.length(); i++) { JSONObject loanFundObject = loanFunds.getJSONObject(i); LoanFund fund = new LoanFund(); fund.setId(loanFundObject.optInt("id")); fund.setValue(loanFundObject.optString("name")); loanFund.add(fund); loanFundNames.add(loanFundObject.optString("name")); loanFundNameIdHashMap.put(fund.getValue(), fund.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> loanFundNameAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, loanFundNames); loanFundNameAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_fund.setAdapter(loanFundNameAdapter); sp_fund.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { fundId = loanFundNameIdHashMap.get(loanFundNames.get(i)); Log.d("fundId " + loanFundNames.get(i), String.valueOf(fundId)); if (fundId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT) .show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); showProgress(false); } @Override public void failure(RetrofitError retrofitError) { Log.d(LOG_TAG, retrofitError.getLocalizedMessage()); showProgress(false); } }); }