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:co.carlosjimenez.android.currencyalerts.app.AddAlertFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_add_alarm, null); ButterKnife.bind(this, dialogView); Bundle arguments = getArguments();/*from ww w . j av a 2 s .c om*/ if (arguments != null) { mCurrencyFrom = arguments.getParcelable(DetailActivityFragment.CURRENCY_FROM); mCurrencyTo = arguments.getParcelable(DetailActivityFragment.CURRENCY_TO); } ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alarm_period_labels, R.layout.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 mSpPeriod.setAdapter(adapter); alertValues = Utility.getAlertSettings(getContext(), false); if (alertValues.getCurrencyFrom().equals(mCurrencyFrom) && alertValues.getCurrencyTo().equals(mCurrencyTo)) { setSelectedPeriod(String.valueOf(alertValues.getPeriod())); mTvFluctuation.setText(String.valueOf(alertValues.getFluctuation())); } else { alertValues = Utility.getAlertSettings(getContext(), true); alertValues.clearAverage(); } // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(dialogView) // Add action buttons .setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { alertValues.setEnabled(true); alertValues.setCurrencyFrom(mCurrencyFrom); alertValues.setCurrencyTo(mCurrencyTo); alertValues.setPeriod(Integer.parseInt(mSelectedPeriod)); alertValues.setFluctuation(Float.parseFloat(mTvFluctuation.getText().toString())); new UpdateAlarmTask(getActivity()).execute(alertValues); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { AddAlertFragment.this.getDialog().cancel(); } }); AlertDialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); return alertDialog; }
From source file:net.palacesoft.cngstation.client.StationActivity.java
public void setCountries(List<String> countriesList) { if (!countriesList.isEmpty()) { ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, simple_spinner_item, countriesList); dataAdapter.setDropDownViewResource(simple_spinner_dropdown_item); countries.setAdapter(dataAdapter); if (currentLocationAddress != null) { String country = currentLocationAddress.getCountryName(); int countryIndex = countriesList.indexOf(country); if (countryIndex > -1) { countries.setSelection(countryIndex); }/*from w w w . j a v a 2 s. c o m*/ } } else { showInfoMessage("Could not load country list"); } }
From source file:com.mifos.mifosxdroid.dialogfragments.loanchargedialog.LoanChargeDialogFragment.java
@Override public void showAllChargesV3(ResponseBody result) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return;/*from w w w . ja v a 2 s . c o m*/ Log.d(LOG_TAG, ""); final List<Charges> charges = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> chargesNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try { reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("chargeOptions")) { JSONArray chargesTypes = obj.getJSONArray("chargeOptions"); for (int i = 0; i < chargesTypes.length(); i++) { JSONObject chargesObject = chargesTypes.getJSONObject(i); Charges charge = new Charges(); charge.setId(chargesObject.optInt("id")); charge.setName(chargesObject.optString("name")); charges.add(charge); chargesNames.add(chargesObject.optString("name")); chargeNameIdHashMap.put(charge.getName(), charge.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> chargesAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, chargesNames); chargesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_charge_name.setAdapter(chargesAdapter); sp_charge_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { Id = chargeNameIdHashMap.get(chargesNames.get(i)); Log.d("chargesoptionss" + chargesNames.get(i), String.valueOf(Id)); if (Id != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_charge), Toast.LENGTH_SHORT) .show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:dk.spaceblog.thenicobomb.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainActivityInstance = this; //Initialize the static instance with the current instance // Set the main menu view setContentView(R.layout.activity_main); // Configure the default values for delay, repeat and intervals. delay = interval = repeat = 1;//from w w w .j av a 2 s .c o m textMessage = phoneNumber = null; // Populate the spinners (http://www.mkyong.com/android/android-spinner-drop-down-list-example/) // Repeat spinner repeatSpinner = (Spinner) findViewById(R.id.repeatSpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.sms_repeat_count, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); repeatSpinner.setAdapter(adapter); repeatSpinner.setOnItemSelectedListener(new SpinnerOnItemSelectedListener(1)); repeatSpinner.setSelection(0); // Delay spinner delaySpinner = (Spinner) findViewById(R.id.delaySpinner); ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.sms_delay, android.R.layout.simple_spinner_item); adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); delaySpinner.setAdapter(adapter2); delaySpinner.setOnItemSelectedListener(new SpinnerOnItemSelectedListener(2)); delaySpinner.setSelection(0); // Interval spinner intervalSpinner = (Spinner) findViewById(R.id.intervalSpinner); ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(this, R.array.sms_interval, android.R.layout.simple_spinner_item); adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); intervalSpinner.setAdapter(adapter3); intervalSpinner.setOnItemSelectedListener(new SpinnerOnItemSelectedListener(3)); intervalSpinner.setSelection(0); //Activate the contact button : ((ImageButton) findViewById(R.id.pick_contact)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // user BoD suggests using Intent.ACTION_PICK instead of .ACTION_GET_CONTENT to avoid the chooser Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // BoD con't: CONTENT_TYPE instead of CONTENT_ITEM_TYPE intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); startActivityForResult(intent, 1); } }); //Check whether the app has the permission to send SMS : this.checkSMSPermission(); }
From source file:com.pimp.calculator.fragments.CurrencyFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); fro = (Spinner) view.findViewById(R.id.fro_spinner); too = (Spinner) view.findViewById(R.id.too_spinner); ArrayAdapter<String> froAdapter = new ArrayAdapter<String>(getActivity(), R.layout.currency_spinner_item, getResources().getStringArray(R.array.currency_exp)); froAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); fro.setAdapter(froAdapter);/* w w w . j a va2s .c om*/ too.setAdapter(froAdapter); fro.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int numFromCurrency = fro.getSelectedItemPosition(); int numToCurrency = too.getSelectedItemPosition(); if (numFromCurrency != numToCurrency) getRate(); else { resultant_TV.setText("1"); SharedPreferences settings = getActivity().getSharedPreferences("MyPrefs", 0); SharedPreferences.Editor editor = settings.edit(); editor.putFloat("rate", 1); editor.apply(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); too.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int numFromCurrency = fro.getSelectedItemPosition(); int numToCurrency = too.getSelectedItemPosition(); if (numFromCurrency != numToCurrency) getRate(); else { resultant_TV.setText("1"); SharedPreferences settings = getActivity().getSharedPreferences("MyPrefs", 0); SharedPreferences.Editor editor = settings.edit(); editor.putFloat("rate", 1); editor.apply(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.enadein.carlogbook.CarLogbook.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); menuList = (ListView) findViewById(R.id.menu); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (savedInstanceState != null) { rotate = savedInstanceState.getBoolean(ROTATE); }/*from w w w . ja v a 2s . c om*/ MenuAdapter menuAdapter = new MenuAdapter(this, 0, buildMenu()); menuList.setAdapter(menuAdapter); menuList.setOnItemClickListener(new DrawerItemClickListener()); initDrawer(); if (!rotate) { mediator.showLogbook(); } ArrayAdapter reportItemsAdapter = ArrayAdapter.createFromResource(CarLogbook.this, R.array.action_list, android.R.layout.simple_spinner_item); reportItemsAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); rotate = false; //TODO initInAppBuilingV3(); }
From source file:com.fjn.magazinereturncandidate.fragments.ProductDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { formatCommon = new FormatCommon(); registerLicenseCommon = new RegisterLicenseCommon(); checkDataCommon = new CheckDataCommon(); //Init custom product detail layout View rootView = inflater.inflate(R.layout.fragment_product_detail, container, false); if (getDialog().getWindow() != null) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); }//from w ww. j a v a2s . com //Get Id textview Product detail TextView txv_jan_cd = (TextView) rootView.findViewById(R.id.txv_jan_cd); TextView txv_group1_name = (TextView) rootView.findViewById(R.id.txv_group1_name); TextView txv_group2_name = (TextView) rootView.findViewById(R.id.txv_group2_name); TextView txv_product_name = (TextView) rootView.findViewById(R.id.txv_product_name); TextView txv_writer_name = (TextView) rootView.findViewById(R.id.txv_writer_name); TextView txv_publisher_name = (TextView) rootView.findViewById(R.id.txv_publisher_name); TextView txv_publish_date = (TextView) rootView.findViewById(R.id.txv_publish_date); TextView txv_price = (TextView) rootView.findViewById(R.id.txv_price); txv_inventory_number = (TextView) rootView.findViewById(R.id.txv_inventory_number); TextView txv_first_supply_date = (TextView) rootView.findViewById(R.id.txv_first_supply_date); TextView txv_last_supply_date = (TextView) rootView.findViewById(R.id.txv_last_supply_date); TextView txv_last_sales_date = (TextView) rootView.findViewById(R.id.txv_last_sales_date); TextView txv_last_order_date = (TextView) rootView.findViewById(R.id.txv_last_order_date); TextView txv_year_rank = (TextView) rootView.findViewById(R.id.txv_year_rank); //TextView txv_joubi = (TextView) rootView.findViewById(R.id.txv_joubi); TextView txv_total_sales = (TextView) rootView.findViewById(R.id.txv_total_sales); TextView txv_total_supply = (TextView) rootView.findViewById(R.id.txv_total_supply); TextView txv_total_return = (TextView) rootView.findViewById(R.id.txv_total_return); TextView txv_location_id = (TextView) rootView.findViewById(R.id.txv_location_id); Button btn_submit_edit = (Button) rootView.findViewById(R.id.btn_submit_edit); Bundle bundle = getArguments(); if (bundle != null) { //Show year_rank String valueYearRank = bundle.getString(Constants.COLUMN_YEAR_RANK); String showYearRank; if (Constants.VALUE_MAX_YEAR_RANK.equals(valueYearRank)) { showYearRank = Constants.SHOW_MAX_YEAR_RANK; } else { showYearRank = String.format("%s?/%s", formatCommon.formatMoney(valueYearRank), formatCommon.formatMoney(String.valueOf(bundle.getInt(Constants.COLUMN_MAX_YEAR_RANK)))); } //Get bundle janCode String janCode = bundle.getString(Constants.COLUMN_JAN_CD); int lenJanCode = 0; String janCodeResult = ""; if (janCode != null) { lenJanCode = janCode.length(); janCodeResult = janCode.substring(0, lenJanCode - 5); } if (lenJanCode != Constants.JAN_18_CHAR) { janCodeResult = janCode; } txv_jan_cd.setText(janCodeResult); txv_group1_name.setText(bundle.getString(Constants.COLUMN_MEDIA_GROUP1_NAME)); txv_group2_name.setText(bundle.getString(Constants.COLUMN_MEDIA_GROUP2_NAME)); txv_product_name.setText(bundle.getString(Constants.COLUMN_GOODS_NAME)); txv_writer_name.setText(bundle.getString(Constants.COLUMN_WRITER_NAME)); txv_publisher_name.setText(bundle.getString(Constants.COLUMN_PUBLISHER_NAME)); txv_publish_date.setText( formatCommon.formatDate(bundle.getString(Constants.COLUMN_SALES_DATE, Constants.BLANK))); if (Constants.BLANK.equals(bundle.getString(Constants.COLUMN_PRICE))) { txv_price.setText(Constants.BLANK); } else { txv_price.setText(String.format("%s%s", Constants.SYMBOL, formatCommon.formatMoney((bundle.getString(Constants.COLUMN_PRICE))))); } if (bundle.getString(Constants.COLUMN_STOCK_COUNT) == null) { txv_inventory_number.setText(""); txv_inventory_number.append(Constants.BLANK); //focus end text } else { txv_inventory_number.setText(""); txv_inventory_number .append(formatCommon.formatMoney(bundle.getString(Constants.COLUMN_STOCK_COUNT)));//focus end text } txv_first_supply_date.setText( formatCommon.formatDate(bundle.getString(Constants.COLUMN_FIRST_SUPPLY_DATE, Constants.BLANK))); txv_last_supply_date.setText( formatCommon.formatDate(bundle.getString(Constants.COLUMN_LAST_SUPPLY_DATE, Constants.BLANK))); txv_last_sales_date.setText( formatCommon.formatDate(bundle.getString(Constants.COLUMN_LAST_SALES_DATE, Constants.BLANK))); txv_last_order_date.setText( formatCommon.formatDate(bundle.getString(Constants.COLUMN_LAST_ORDER_DATE, Constants.BLANK))); txv_year_rank.setText(showYearRank); //txv_joubi.setText(formatJoubi(bundle.getString(Constants.COLUMN_JOUBI))); txv_total_sales.setText(formatCommon.formatMoney(bundle.getString(Constants.COLUMN_TOTAL_SALES))); txv_total_supply.setText(formatCommon.formatMoney(bundle.getString(Constants.COLUMN_TOTAL_SUPPLY))); txv_total_return.setText(formatCommon.formatMoney(bundle.getString(Constants.COLUMN_TOTAL_RETURN))); txv_location_id.setText(bundle.getString(Constants.COLUMN_LOCATION_ID)); //get position positionEdit = bundle.getInt(Constants.POSITION_EDIT_PRODUCT); //get flag OCR flagSwitchOCR = getArguments().getString(Constants.FLAG_SWITCH_OCR); } loadItems(); // Set adapter for combo box with array ArrayAdapter<String> adapter1 = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, arr); // Set item selected adapter1.setDropDownViewResource(android.R.layout.simple_list_item_single_choice); // Set button click btn_submit_edit.setOnClickListener(this); hsmDecoder = HSMDecoder.getInstance(getActivity()); return rootView; }
From source file:com.openerp.base.login.Login.java
/** * Load database list./*from w w w . ja v a2s .co m*/ */ private void loadDatabaseList() { try { openerp = new OpenERP(openERPServerURL); List<String> dbList = new JSONDataHelper().arrayToStringList(openerp.getDatabaseList()); dbList.add(0, getActivity().getString(R.string.login_select_database)); ArrayAdapter<String> dbAdapter = new ArrayAdapter<String>(getActivity(), R.layout.spinner_custom_layout, dbList); dbAdapter.setDropDownViewResource(R.layout.spinner_custom_layout); dbListSpinner.setAdapter(dbAdapter); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mifos.mifosxdroid.dialogfragments.ChargeDialogFragment.java
private void inflateChargesSpinner() { showProgress(true);/* ww w .j a va 2 s . c o m*/ App.apiManager.getAllChargesV2(clientId, 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, "Charges Loaded Successfully"); final List<Charges> charges = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> chargesNames = 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("chargeOptions")) { JSONArray chargesTypes = obj.getJSONArray("chargeOptions"); for (int i = 0; i < chargesTypes.length(); i++) { JSONObject chargesObject = chargesTypes.getJSONObject(i); Charges charge = new Charges(); charge.setId(chargesObject.optInt("id")); charge.setName(chargesObject.optString("name")); charges.add(charge); chargesNames.add(chargesObject.optString("name")); chargeNameIdHashMap.put(charge.getName(), charge.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, e.getMessage()); } final ArrayAdapter<String> chargesAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, chargesNames); chargesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_charge_name.setAdapter(chargesAdapter); sp_charge_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { Id = chargeNameIdHashMap.get(chargesNames.get(i)); Log.d("chargesoptionss" + chargesNames.get(i), String.valueOf(Id)); if (Id != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_charge), 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); } }); }
From source file:edu.asu.msse.sgowdru.moviesqldb.SearchMovie.java
public void searchButtonClicked(View view) { String searchString = info[0].getText().toString(); android.util.Log.w(getClass().getSimpleName(), searchString); try {//from ww w .j ava 2 s . c o m cur = crsDB.rawQuery("select Title from Movies where Title='" + searchString + "';", new String[] {}); android.util.Log.w(getClass().getSimpleName(), searchString); //If the Movie Exists in the Local Database, we will retrieve it from the Local DB if (cur.getCount() != 0) { //Raise toast message that the movie is already present in local DB text = " already present in DB, Retrieving.."; Toast toast = Toast.makeText(context, "Movie " + searchString + text, duration); toast.show(); //Retrieving the Movie since we know that the movie exists in DB cur = crsDB.rawQuery("select Title, Genre, Years, Rated, Actors from Movies where Title = ?;", new String[] { searchString }); //Movie Already present hence disabling the Add Button btn.setEnabled(false); //Move the Cursor and set the Fields cur.moveToNext(); info[1].setText(cur.getString(0)); info[2].setText(cur.getString(1)); info[3].setText(cur.getString(2)); info[4].setText(cur.getString(4)); //Set the Ratings dropdown if (cur.getString(3).equals("PG")) dropdown.setSelection(0); else if (cur.getString(3).equals("PG-13")) dropdown.setSelection(1); else if (cur.getString(3).equals("R")) dropdown.setSelection(2); } //If the Movie Does not exist in the Local Database, we will retrieve it from the OMDB else { //Movie not present in local DB, raise a toast message text = " being retrieved from OMDB now."; Toast toast = Toast.makeText(context, "Movie " + searchString + text, duration); toast.show(); //Encode the search string to be appropriate to be placed in a url String encodedUrl = null; try { encodedUrl = URLEncoder.encode(searchString, "UTF-8"); } catch (UnsupportedEncodingException e) { android.util.Log.e(getClass().getSimpleName(), e.getMessage()); } //ASync thread running the query from OMDB and retrieving the movie details as JSON JSONObject result = new MovieGetInfoAsync() .execute("http://www.omdbapi.com/?t=\"" + encodedUrl + "\"&r=json").get(); //Check if the Movie query was successful if (result.getString("Response").equals("True")) { info[1].setText(result.getString("Title")); info[2].setText(result.getString("Genre")); info[3].setText(result.getString("Year")); info[4].setText(result.getString("Actors")); //Ratings field is of type Spinner class with field values (PG, PG-13, R rated) ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Ratings, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dropdown.setAdapter(adapter); if (result.getString("Rated").equals("PG")) dropdown.setSelection(0); else if (result.getString("Rated").equals("PG-13")) dropdown.setSelection(1); else if (result.getString("Rated").equals("R")) dropdown.setSelection(2); } //Search query was unsuccessful in getting movie with such a name else if (result.getString("Response").equals("False")) { //Raise a toast message text = " not present in OMDB, You can add it manually!"; toast = Toast.makeText(context, "Movie " + searchString + text, duration); toast.show(); } } } catch (Exception e) { android.util.Log.w(getClass().getSimpleName(), e.getMessage()); } }