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.df.app.carCheck.VehicleInfoLayout.java
/** * edit/*w w w. j ava2s . co m*/ */ private void setSeriesEdit(final Manufacturer manufacturer) { // adaptermanufacturerseries?? final ArrayAdapter<String> adapter; if (manufacturer == 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, manufacturer.getSeriesNames()); } final Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message message) { if (message.what == 0) { seriesEdit.setText(""); modelEdit.setText(""); } else { Series series = manufacturer.serieses.get(message.what - 1); seriesEdit.setText(series.name); // ??edit if (lastSeriesIndex != message.what) { modelEdit.setText(""); } setModelEdit(series); } lastSeriesIndex = message.what; return true; } }); // ????series if (manufacturer.getSeriesNames().size() == 2) { lastSeriesIndex = 1; seriesEdit.setText(manufacturer.getSeriesNames().get(1)); setModelEdit(manufacturer.serieses.get(0)); return; } // ?series else { showListDialog(R.string.chooseSeries, adapter, handler); } // manufacturerEdit seriesEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { showListDialog(R.string.chooseSeries, adapter, handler); } }); }
From source file:org.ros.android.app_chooser.ExchangeActivity.java
private void update(ArrayList<ExchangeApp> availableApps, ArrayList<ExchangeApp> installedApps) { int nInstalledApps = 0; int nAvailableApps = 0; int i = 0;//from w w w .java 2s .c o m for (ExchangeApp a : installedApps) { if (!a.hidden) { nInstalledApps++; } } installed_application_list = new String[nInstalledApps]; installed_application_display = new String[nInstalledApps]; for (ExchangeApp a : installedApps) { if (!a.hidden) { installed_application_list[i] = a.name; if (!a.version.equals(a.latest_version)) { installed_application_display[i] = a.display_name + " (Upgradable)"; } else { installed_application_display[i] = a.display_name; } i = i + 1; } } installedAppListView.setTextFilterEnabled(true); final String[] installed_application_list_array = installed_application_list; final String[] installed_application_display_array = installed_application_display; ArrayAdapter ad = new ArrayAdapter(this, android.R.layout.simple_list_item_1, installed_application_display_array); installedAppListView.setAdapter(ad); registerForContextMenu(installedAppListView); registerForContextMenu(availableAppListView); installedAppListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView adapter, View view, int index, long id) { appSelected = installed_application_list_array[index]; appSelectedDisplay = installed_application_display_array[index]; Log.i("ExchangeActivity", appSelected); ExchangeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { update(availableAppsCache, installedAppsCache); installedAppsView.setVisibility(appExchangeView.GONE); appExchangeView.setVisibility(appExchangeView.GONE); appDetailView.setVisibility(appDetailView.VISIBLE); exchangeAppDetailTextView.setText("Loading..."); ((ImageView) ExchangeActivity.this.findViewById(R.id.exchange_icon)) .setImageResource(R.drawable.icon); } }); updateAppDetails(); } }); //// i = 0; for (ExchangeApp a : availableApps) { if (!a.hidden) { nAvailableApps++; } } available_application_list = new String[nAvailableApps]; available_application_display = new String[nAvailableApps]; for (ExchangeApp a : availableApps) { if (!a.hidden) { available_application_list[i] = a.name; available_application_display[i] = a.display_name; i = i + 1; } } availableAppListView.setTextFilterEnabled(true); final String[] available_application_list_array = available_application_list; final String[] available_application_display_array = available_application_display; ad = new ArrayAdapter(this, android.R.layout.simple_list_item_1, available_application_display_array); availableAppListView.setAdapter(ad); availableAppListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView adapter, View view, int index, long id) { appSelected = available_application_list_array[index]; appSelectedDisplay = available_application_display_array[index]; Log.i("ExchangeActivity", appSelected); ExchangeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { update(availableAppsCache, installedAppsCache); installedAppsView.setVisibility(appExchangeView.GONE); appExchangeView.setVisibility(appExchangeView.GONE); appDetailView.setVisibility(appDetailView.VISIBLE); exchangeAppDetailTextView.setText("Loading..."); ((ImageView) ExchangeActivity.this.findViewById(R.id.exchange_icon)) .setImageResource(R.drawable.icon); } }); updateAppDetails(); } }); availableAppsCache = availableApps; installedAppsCache = installedApps; if (appInList(installedApps, appSelected)) { //Is installed exchangeAppNameView.setText(appSelectedDisplay + " (Installed)"); installAppButton.setVisibility(appExchangeView.GONE); for (ExchangeApp a : installedApps) { if (a.name == appSelected && !a.version.equals(a.latest_version)) { exchangeAppNameView.setText(a.display_name + " (Installed, Upgrade Available)"); installAppButton.setVisibility(appExchangeView.VISIBLE); } } uninstallAppButton.setVisibility(appDetailView.VISIBLE); } else if (appInList(availableApps, appSelected)) { //Is available exchangeAppNameView.setText(appSelectedDisplay + " (Not Installed)"); installAppButton.setVisibility(appExchangeView.VISIBLE); uninstallAppButton.setVisibility(appDetailView.GONE); } else { appSelected = null; //Bad app! appSelectedDisplay = null; } if (appSelected == null) { revertToState(); } }
From source file:com.sakisds.icymonitor.activities.AddNotificationActivity.java
private void setAdapter(Spinner spinner, String[] source) { ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, source); spinner.setAdapter(adapter);/*from w w w. j a v a 2 s .c o m*/ }
From source file:com.cwp.cmoneycharge.activity.AddPayActivity.java
private void updatetype() { // initData(userid);/*from ww w . ja v a 2 s . c o m*/ spdata = spdatalist.toArray(new String[spdatalist.size()]);// tb_itypeid? adapter = new ArrayAdapter<String>(AddPayActivity.this, R.layout.spinner, spdata); // ?? spType.setAdapter(adapter); if (Selection > 0) { spType.setSelection(Selection);// } }
From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java
private void setAdapter(final int count) { ArrayAdapter<String> itemsAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items) { @NonNull//w w w . ja v a2 s .c o m @Override public View getView(final int position, View convertView, @NonNull ViewGroup parent) { View v = super.getView(position, convertView, parent); if (position == count) { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent_trans)); } else { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.color_trans)); } return v; } }; lvItems.setAdapter(itemsAdapter); }
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
private ArrayAdapter<String> popupMenuAdapter(String itemTagArray[]) { ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, itemTagArray) {// ww w . j av a2 s .c o m @Override public View getView(int position, View convertView, ViewGroup parent) { // setting the ID and text for every items in the list String item = getItem(position); String[] itemArr = item.split("::"); String text = itemArr[0]; String id = itemArr[1]; // visual settings for the list item TextView listItem = new TextView(AnalyzeActivity.this); if (id.equals("0")) { listItem.setText(text); listItem.setTag(id); listItem.setTextSize(listItemTitleTextSize / DPRatio); listItem.setPadding(5, 5, 5, 5); listItem.setTextColor(Color.GREEN); listItem.setGravity(android.view.Gravity.CENTER); } else { listItem.setText(text); listItem.setTag(id); listItem.setTextSize(listItemTextSize / DPRatio); listItem.setPadding(5, 5, 5, 5); listItem.setTextColor(Color.WHITE); listItem.setGravity(android.view.Gravity.CENTER); } return listItem; } }; return adapter; }
From source file:com.mifos.mifosxdroid.online.LoanAccountFragment.java
private void inflateLoanPurposeSpinner() { showProgress(true);//from ww w . j a va2s. c om 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<LoanPurposeOptions> loanPurposeOptionsType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> loanPurposeOptionsTypeNames = 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("loanPurposeOptions")) { JSONArray loanPurposeOptionsTypes = obj.getJSONArray("loanPurposeOptions"); for (int i = 0; i < loanPurposeOptionsTypes.length(); i++) { JSONObject loanPurposeOptionsTypesObject = loanPurposeOptionsTypes.getJSONObject(i); LoanPurposeOptions loanpurpose = new LoanPurposeOptions(); loanpurpose.setId(loanPurposeOptionsTypesObject.optInt("id")); loanpurpose.setName(loanPurposeOptionsTypesObject.optString("name")); loanPurposeOptionsType.add(loanpurpose); loanPurposeOptionsTypeNames.add(loanPurposeOptionsTypesObject.optString("name")); loanPurposeNameIdHashMap.put(loanpurpose.getName(), loanpurpose.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> loanPTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, loanPurposeOptionsTypeNames); loanPTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_loan_purpose.setAdapter(loanPTypeAdapter); sp_loan_purpose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { loanPurposeId = loanPurposeNameIdHashMap.get(loanPurposeOptionsTypeNames.get(i)); Log.d("loanpurpose" + loanPurposeOptionsTypeNames.get(i), String.valueOf(loanPurposeId)); if (loanPurposeId != -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); } }); }
From source file:com.ichi2.anki.NoteEditor.java
@Override protected void onCollectionLoaded(Collection col) { super.onCollectionLoaded(col); this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Intent intent = getIntent();//from ww w . j a va 2 s .c o m Timber.d("onCollectionLoaded: caller: %d", mCaller); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); registerExternalStorageListener(); View mainView = findViewById(android.R.id.content); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); } mFieldsLayoutContainer = (LinearLayout) findViewById(R.id.CardEditorEditFieldsLayout); mTagsButton = (TextView) findViewById(R.id.CardEditorTagText); mCardsButton = (TextView) findViewById(R.id.CardEditorCardsText); mCardsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Timber.i("NoteEditor:: Cards button pressed. Opening template editor"); showCardTemplateEditor(); } }); Preferences.COMING_FROM_ADD = false; mAedictIntent = false; switch (mCaller) { case CALLER_NOCALLER: Timber.e("no caller could be identified, closing"); finishWithoutAnimation(); return; case CALLER_REVIEWER: mCurrentEditedCard = AbstractFlashcardViewer.getEditorCard(); if (mCurrentEditedCard == null) { finishWithoutAnimation(); return; } mEditorNote = mCurrentEditedCard.note(); mAddNote = false; break; case CALLER_STUDYOPTIONS: case CALLER_DECKPICKER: mAddNote = true; break; case CALLER_CARDBROWSER_EDIT: mCurrentEditedCard = CardBrowser.sCardBrowserCard; if (mCurrentEditedCard == null) { finishWithoutAnimation(); return; } mEditorNote = mCurrentEditedCard.note(); mAddNote = false; break; case CALLER_CARDBROWSER_ADD: mAddNote = true; break; case CALLER_CARDEDITOR: mAddNote = true; break; case CALLER_CARDEDITOR_INTENT_ADD: fetchIntentInformation(intent); if (mSourceText == null) { finishWithoutAnimation(); return; } if (mSourceText[0].equals("Aedict Notepad") && addFromAedict(mSourceText[1])) { finishWithoutAnimation(); return; } mAddNote = true; break; } // Note type Selector mNoteTypeSpinner = (Spinner) findViewById(R.id.note_type_spinner); mAllModelIds = new ArrayList<Long>(); final ArrayList<String> modelNames = new ArrayList<String>(); ArrayList<JSONObject> models = getCol().getModels().all(); Collections.sort(models, new JSONNameComparator()); for (JSONObject m : models) { try { modelNames.add(m.getString("name")); mAllModelIds.add(m.getLong("id")); } catch (JSONException e) { throw new RuntimeException(e); } } ArrayAdapter<String> noteTypeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, modelNames); mNoteTypeSpinner.setAdapter(noteTypeAdapter); noteTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Deck Selector TextView deckTextView = (TextView) findViewById(R.id.CardEditorDeckText); // If edit mode and more than one card template distinguish between "Deck" and "Card deck" try { if (!mAddNote && mEditorNote.model().getJSONArray("tmpls").length() > 1) { deckTextView.setText(R.string.CardEditorCardDeck); } } catch (JSONException e1) { throw new RuntimeException(); } mNoteDeckSpinner = (Spinner) findViewById(R.id.note_deck_spinner); mAllDeckIds = new ArrayList<Long>(); final ArrayList<String> deckNames = new ArrayList<String>(); ArrayList<JSONObject> decks = getCol().getDecks().all(); Collections.sort(decks, new JSONNameComparator()); for (JSONObject d : decks) { try { // add current deck and all other non-filtered decks to deck list long thisDid = d.getLong("id"); long currentDid = getCol().getDecks().current().getLong("id"); if (d.getInt("dyn") == 0 || (!mAddNote && thisDid == currentDid)) { deckNames.add(d.getString("name")); mAllDeckIds.add(thisDid); } } catch (JSONException e) { throw new RuntimeException(e); } } ArrayAdapter<String> noteDeckAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, deckNames); mNoteDeckSpinner.setAdapter(noteDeckAdapter); noteDeckAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mNoteDeckSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { // Timber.i("NoteEditor:: onItemSelected() fired on mNoteDeckSpinner with pos = "+Integer.toString(pos)); mCurrentDid = mAllDeckIds.get(pos); } @Override public void onNothingSelected(AdapterView<?> parent) { // Do Nothing } }); setDid(mEditorNote); setNote(mEditorNote); // Set current note type and deck positions in spinners int position; try { position = mAllModelIds.indexOf(mEditorNote.model().getLong("id")); } catch (JSONException e) { throw new RuntimeException(e); } // set selection without firing selectionChanged event // nb: setOnItemSelectedListener needs to occur after this mNoteTypeSpinner.setSelection(position, false); if (mAddNote) { mNoteTypeSpinner.setOnItemSelectedListener(new SetNoteTypeListener()); setTitle(R.string.cardeditor_title_add_note); // set information transferred by intent String contents = null; if (mSourceText != null) { if (mAedictIntent && (mEditFields.size() == 3) && mSourceText[1].contains("[")) { contents = mSourceText[1].replaceFirst("\\[", "\u001f" + mSourceText[0] + "\u001f"); contents = contents.substring(0, contents.length() - 1); } else if (mEditFields.size() > 0) { mEditFields.get(0).setText(mSourceText[0]); if (mEditFields.size() > 1) { mEditFields.get(1).setText(mSourceText[1]); } } } else { contents = intent.getStringExtra(EXTRA_CONTENTS); } if (contents != null) { setEditFieldTexts(contents); } } else { mNoteTypeSpinner.setOnItemSelectedListener(new EditNoteTypeListener()); setTitle(R.string.cardeditor_title_edit_card); } ((LinearLayout) findViewById(R.id.CardEditorTagButton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Timber.i("NoteEditor:: Tags button pressed... opening tags editor"); showTagsDialog(); } }); if (!mAddNote && mCurrentEditedCard != null) { Timber.i("NoteEditor:: Edit note activity successfully started with card id %d", mCurrentEditedCard.getId()); } }
From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java
/** * Set the GUI-Content from <code>mTimer</code> *///from w w w. j a v a 2s . c om protected void reload() { // Name mName.setText(mTimer.getString(Timer.KEY_NAME)); mName.setHint(R.string.title); // Description mDescription.setText(mTimer.getString(Timer.KEY_DESCRIPTION)); mDescription.setHint(R.string.description); // Enabled int disabled = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_DISABLED)); if (disabled == 0) { mEnabled.setChecked(true); } else { mEnabled.setChecked(false); } int zap = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_JUST_PLAY)); if (zap == 1) { mZap.setChecked(true); } else { mZap.setChecked(false); } mService.setText(mTimer.getString(Timer.KEY_SERVICE_NAME)); // Afterevents ArrayAdapter<CharSequence> aaAfterevent = ArrayAdapter.createFromResource(getAppCompatActivity(), R.array.afterevents, android.R.layout.simple_spinner_item); aaAfterevent.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mAfterevent.setAdapter(aaAfterevent); int aeValue = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_AFTER_EVENT)); mAfterevent.setSelection(aeValue); // Locations ArrayAdapter<String> aaLocations = new ArrayAdapter<>(getAppCompatActivity(), android.R.layout.simple_spinner_item, DreamDroid.getLocations()); aaLocations.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLocation.setAdapter(aaLocations); String timerLoc = mTimer.getString(Timer.KEY_LOCATION); for (int i = 0; i < DreamDroid.getLocations().size(); i++) { String loc = DreamDroid.getLocations().get(i); if (timerLoc != null) { if (timerLoc.equals(loc)) { mLocation.setSelection(i); } } } // Start and Endtime mBegin = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_BEGIN)); mEnd = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_END)); Date dateBegin = new Date(((long) mBegin) * 1000); Date dateEnd = new Date(((long) mEnd) * 1000); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm"); mStartDate.setText(dateFormat.format(dateBegin)); mStartTime.setText(timeFormat.format(dateBegin)); mEndDate.setText(dateFormat.format(dateEnd)); mEndTime.setText(timeFormat.format(dateEnd)); // Repeatings int repeatedValue = 0; try { repeatedValue = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_REPEATED)); } catch (NumberFormatException ex) { } String repeatedText = getRepeated(repeatedValue); mRepeatings.setText(repeatedText); String text = mTimer.getString(Timer.KEY_TAGS); if (text == null) { text = ""; } mTags.setText(text); String[] tags = text.split(" "); Collections.addAll(mSelectedTags, tags); }
From source file:com.zira.registration.VehicleInformationActivity.java
protected void setApapterForVehicleYear(String year) { int yearIntValue; try {/*from w w w.ja v a 2 s . c o m*/ yearIntValue = Integer.parseInt(year); } catch (Exception e) { yearIntValue = 0; } ArrayList<String> years = new ArrayList<String>(); years.add("Choose Vehicle Year"); if (yearIntValue > 0) { for (int i = yearIntValue; i <= Calendar.getInstance().get(Calendar.YEAR); i++) { years.add(String.valueOf(i)); } } /******************************/ if (years.size() > 0) { String gettingVehicleYear = mProfileInfoModel.getVechile_year(); // if(gettingVehicleYear.equals("")) // { // gettingVehicleYear=prefs3.getString("year", ""); // } int i = 0; for (String s : years) { String vehicleyear = s; if (gettingVehicleYear.equals(vehicleyear)) { gettingVehicleYearPosition = i; } i++; } } /******************************/ ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_list, years); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); vehiclemodalYearSpinner.setAdapter(dataAdapter); if (value == 1) if (vehicle_flag > 1) { vehiclemodalYearSpinner.setSelection(0); } else { if (years.size() > gettingVehicleYearPosition) { vehiclemodalYearSpinner.setSelection(gettingVehicleYearPosition); } } }