List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects)
From source file:com.jbsoft.farmtotable.FarmToTableActivity.java
private void initListNav() { ArrayList<String> items = new ArrayList<String>(); ArrayAdapter<String> nav = null; ActionBar bar = getSupportActionBar(); for (int type : MAP_TYPE_NAMES) { items.add(getString(type));/*from w ww . j a v a 2 s . co m*/ } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { nav = new ArrayAdapter<String>(bar.getThemedContext(), android.R.layout.simple_spinner_item, items); } else { nav = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items); } nav.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); }
From source file:net.reichholf.dreamdroid.activities.TimerEditActivity.java
/** * Set the GUI-Content from <code>mTimer</code> *//*from w ww .java 2 s .co m*/ private void reload() { // Name mName.setText(mTimer.getString(Timer.NAME)); mName.setHint(R.string.title); // Description mDescription.setText(mTimer.getString(Timer.DESCRIPTION)); mDescription.setHint(R.string.description); // Enabled int disabled = new Integer(mTimer.getString(Timer.DISABLED)); if (disabled == 0) { mEnabled.setChecked(true); } else { mEnabled.setChecked(false); } mService.setText(mTimer.getString(Timer.SERVICE_NAME)); // Afterevents ArrayAdapter<CharSequence> aaAfterevent = ArrayAdapter.createFromResource(this, R.array.afterevents, android.R.layout.simple_spinner_item); aaAfterevent.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mAfterevent.setAdapter(aaAfterevent); int aeValue = new Integer(mTimer.getString(Timer.AFTER_EVENT)).intValue(); mAfterevent.setSelection(aeValue); // Locations ArrayAdapter<String> aaLocations = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, DreamDroid.LOCATIONS); aaLocations.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLocation.setAdapter(aaLocations); String timerLoc = mTimer.getString(Timer.LOCATION); for (int i = 0; i < DreamDroid.LOCATIONS.size(); i++) { String loc = DreamDroid.LOCATIONS.get(i); if (timerLoc != null) { if (timerLoc.equals(loc)) { mLocation.setSelection(i); } } } // Start and Endtime int begin = new Integer(mTimer.getString(Timer.BEGIN)); int end = new Integer(mTimer.getString(Timer.END)); long b = ((long) begin) * 1000; long e = ((long) end) * 1000; Date dateBegin = new Date(b); Date dateEnd = new Date(e); mStart.setText(dateBegin.toLocaleString()); mEnd.setText(dateEnd.toLocaleString()); // Repeatings int repeatedValue = new Integer(mTimer.getString(Timer.REPEATED)); String repeatedText = getRepeated(repeatedValue); mRepeatings.setText(repeatedText); String text = mTimer.getString(Timer.TAGS); if (text == null) { text = ""; } mTags.setText(text); String[] tags = text.split(" "); for (String tag : tags) { mSelectedTags.add(tag); } }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
private void inflateFrequencyPeriodSpinner(ResponseBody result) { final List<TermFrequencyTypeOptions> termFrequencyType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> termFrequencyTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try {// ww w .j ava 2 s . c o m 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("termFrequencyTypeOptions")) { JSONArray termFrequencyTypes = obj.getJSONArray("termFrequencyTypeOptions"); for (int i = 0; i < termFrequencyTypes.length(); i++) { JSONObject termFrequencyTypeObject = termFrequencyTypes.getJSONObject(i); TermFrequencyTypeOptions termFrequency = new TermFrequencyTypeOptions(); termFrequency.setId(termFrequencyTypeObject.optInt("id")); termFrequency.setValue(termFrequencyTypeObject.optString("value")); termFrequencyType.add(termFrequency); termFrequencyTypeNames.add(termFrequencyTypeObject.optString("value")); termFrequencyTypeIdHashMap.put(termFrequency.getValue(), termFrequency.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> termFrequencyTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, termFrequencyTypeNames); termFrequencyTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_payment_periods.setAdapter(termFrequencyTypeAdapter); sp_payment_periods.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { loanTermFrequency = termFrequencyTypeIdHashMap.get(termFrequencyTypeNames.get(i)); Log.d("termFrequencyTypeId" + termFrequencyTypeNames.get(i), String.valueOf(loanTermFrequency)); if (loanTermFrequency != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:org.elasticdroid.SshConnectorView.java
/** * Method called to populate the open ports spinner in the UI *///from w w w.ja v a 2 s . c o m private void populateSpinner() { if (openPorts == null) { return; } int selectedIndex = 0; //set selected index to index of port 22 if available. Spinner portSpinner = (Spinner) findViewById(R.id.sshConnectorPortSpinner); if (openPorts.contains("22")) { Log.d(TAG, "Found port 22 in openPorts.Setting as selected."); selectedIndex = openPorts.indexOf("22"); } //create an ArrayAdapter<String> to hold this ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, openPorts); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); portSpinner.setAdapter(spinnerAdapter); portSpinner.setSelection(selectedIndex); //0 if port 22 unavailable, else indexof(port22) }
From source file:com.df.app.carCheck.VehicleInfoLayout.java
/** * edit//w w w . j a v a 2s .c om */ private void setModelEdit(final Series series) { // adapterseriesmodel?? final ArrayAdapter<String> adapter; if (series == null) { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1, Helper.getEmptyStringList()); } else { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1, series.getModelNames()); } final Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message message) { lastModelIndex = message.what; if (message.what == 0) { modelEdit.setText(""); } else { Model model = series.models.get(message.what - 1); modelEdit.setText(model.name); } return true; } }); // ??? if (series.getModelNames().size() == 2) { lastModelIndex = 1; modelEdit.setText(series.getModelNames().get(1)); return; } // ?model else { showListDialog(R.string.chooseModel, adapter, handler); } // manufacturerEdit modelEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { showListDialog(R.string.chooseModel, adapter, handler); } }); }
From source file:com.zira.registration.VehicleInformationActivity.java
protected void setApapterForVehicleModel(ArrayList<ModelArray> vehicleModals) { /******************************/ if (vehicleArrayList.size() > 0) { //edit/* w ww . j a v a2 s. c o m*/ // String gettingVehicleModel=mProfileInfoModel.getVechile_model(); String gettingVehicleModel = mProfileInfoModel.getVechile_modelID(); // if(gettingVehicleModel.equals("0")) // { // gettingVehicleModel=prefs3.getString("modelid", ""); // } int i = 0; for (ModelArray vehicle : vehicleArrayList.get(gettingVehicleMakePosition).getListModalData()) { //String vehicleMode=vehicle.getVehiclemodalName(); String vehicleMode = vehicle.getVehiclemodelID(); if (gettingVehicleModel.equals(vehicleMode)) { gettingVehicleModelPosition = i; System.err.println("vehicelmodel=" + i); } i++; } } /******************************/ ArrayAdapter<ModelArray> dataAdapter = new ArrayAdapter<ModelArray>(this, R.layout.spinner_list, vehicleModals); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); vehiclemodalNameSpinner.setAdapter(dataAdapter); if (value == 1) if (vehicle_flag > 1) { gettingVehicleModelPosition = 0; vehiclemodalNameSpinner.setSelection(gettingVehicleModelPosition); String year; if (vehicleModals.size() > 0) year = vehicleModals.get(gettingVehicleModelPosition).getVehiclemodalYear(); else year = "0"; setApapterForVehicleYear(year); } else { if (vehicleModals.size() > gettingVehicleModelPosition) { vehiclemodalNameSpinner.setSelection(gettingVehicleModelPosition); String year; if (vehicleModals.size() > 0) year = vehicleModals.get(gettingVehicleModelPosition).getVehiclemodalYear(); else year = "0"; setApapterForVehicleYear(year); } } // vehiclemodalNameSpinner.setSelection(Integer.parseInt(mProfileInfoModel.getVechile_modelID())); }
From source file:com.mifos.mifosxdroid.online.GroupLoanAccountFragment.java
private void inflateInterestCalculationPeriodSpinner() { showProgress(true);/*w w w .java 2 s. co m*/ App.apiManager.getGroupLoansAccountTemplate(groupId, 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<InterestCalculationPeriodType> interestCalculationPeriodType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> interestCalculationPeriodTypeNames = 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("interestCalculationPeriodTypeOptions")) { JSONArray interestCalculationPeriodTypes = obj .getJSONArray("interestCalculationPeriodTypeOptions"); for (int i = 0; i < interestCalculationPeriodTypes.length(); i++) { JSONObject interestCalculationPeriodTypeObject = interestCalculationPeriodTypes .getJSONObject(i); InterestCalculationPeriodType interestCalculationPeriod = new InterestCalculationPeriodType(); interestCalculationPeriod.setId(interestCalculationPeriodTypeObject.optInt("id")); interestCalculationPeriod .setValue(interestCalculationPeriodTypeObject.optString("value")); interestCalculationPeriodType.add(interestCalculationPeriod); interestCalculationPeriodTypeNames .add(interestCalculationPeriodTypeObject.optString("value")); interestCalculationPeriodTypeIdHashMap.put(interestCalculationPeriod.getValue(), interestCalculationPeriod.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> interestCalculationPeriodTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, interestCalculationPeriodTypeNames); interestCalculationPeriodTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_interestcalculationperiod.setAdapter(interestCalculationPeriodTypeAdapter); sp_interestcalculationperiod.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { interestCalculationPeriodTypeId = interestCalculationPeriodTypeIdHashMap .get(interestCalculationPeriodTypeNames.get(i)); Log.d("interestCalculation " + interestCalculationPeriodTypeNames.get(i), String.valueOf(interestCalculationPeriodTypeId)); if (interestCalculationPeriodTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_interestCalculationPeriod), 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:com.sssemil.sonyirremote.ir.ir.java
public void onRemoveClick(View view) { try {/*from w ww. jav a2s. co m*/ Toast.makeText(this, item, Toast.LENGTH_SHORT).show(); String[] remove = { "rm", "-rf", irpath + item }; try { Process p = Runtime.getRuntime().exec(remove); Log.i("rm", "Waiting... " + irpath + item); p.waitFor(); Log.i("rm", "Done! " + irpath + item); } catch (Exception e) { Log.e("rm", "Failed! " + irpath + item); e.printStackTrace(); } spinner = ((Spinner) findViewById(R.id.spinner)); localArrayList1 = new ArrayList(); localArrayList1.remove(item); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, localArrayList1); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.done)); builder.setMessage(getString(R.string.done_removing) + " " + item + " " + getString(R.string.files)); builder.setPositiveButton("OK", null); AlertDialog dialog = builder.show(); TextView messageView = (TextView) dialog.findViewById(android.R.id.message); messageView.setGravity(Gravity.CENTER); } catch (NullPointerException ex) { ex.printStackTrace(); AlertDialog.Builder adb = new AlertDialog.Builder(this); adb.setTitle(getString(R.string.error)); adb.setMessage(getString(R.string.you_need_to_select)); adb.setIcon(android.R.drawable.ic_dialog_alert); adb.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); adb.show(); } }
From source file:com.zira.registration.VehicleInformationActivity.java
protected void setApapterForCountry() { ArrayAdapter<Country> dataAdapter = new ArrayAdapter<Country>(this, R.layout.spinner_list, countryList); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); countryNameSpinner.setAdapter(dataAdapter); if (SingleTon.getInstance().isEdited()) { countryNameSpinner.setSelection(gettingCountryPosition); }/* w w w . j a va2 s . c o m*/ }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
@Override public void showAllLoans(List<LoanProducts> loans) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return;/*from ww w. j a va 2 s.c o m*/ final List<String> loansList = new ArrayList<String>(); for (LoanProducts loansname : loans) { loansList.add(loansname.getName()); loansNameIdHashMap.put(loansname.getName(), loansname.getId()); } ArrayAdapter<String> loansAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, loansList); loansAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_lproduct.setAdapter(loansAdapter); sp_lproduct.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { productId = loansNameIdHashMap.get(loansList.get(i)); Log.d("productId " + loansList.get(i), String.valueOf(productId)); if (productId != -1) { inflateLoanPurposeSpinner(); } else { Toast.makeText(getActivity(), getString(R.string.error_select_loan), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }