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.jlt.patadata.ChooseDatasetFragment.java
/** Other Methods */ // begin method initializeUI private void initializeUI(View rootView) { // 1. initialize UI // 1a. initialize the datasets spinner // 1a1. create an ArrayAdapter using the World Bank datasets and a default spinner layout // 1a2. specify the layout to use when the list of choices appears // 1a3. apply the adapter to the spinner // 1a4. set as selected the first item on the spinner // 1b. initialize the start year spinner // 1b1. create an ArrayAdapter using the start years and a default spinner layout // 1b2. specify the layout to use when the list of choices appears // 1b3. apply the adapter to the spinner // 1b4. set as selected the first item on the spinner // 1c. initialize the end year spinner // 1c1. create an ArrayAdapter using the end years and a default spinner layout // 1c2. specify the layout to use when the list of choices appears // 1c3. apply the adapter to the spinner // 1c4. set as selected the first item on the spinner // 1d. initialize the search fab // 1d1. when the fab is touched // 1d1a. validate the spinner choices and act accordingly // 1e. set the bar title to be the name of the app // 1a. initialize the datasets spinner datasetsSpinner = (Spinner) rootView.findViewById(R.id.fcd_s_datasets); // 1a1. create an ArrayAdapter using the World Bank datasets and a default spinner layout ArrayAdapter<String> datasetsArrayAdapter = new ArrayAdapter<String>( getActivity(),/*from w w w. jav a2 s . c om*/ android.R.layout.simple_spinner_item, WorldBankJSONUtils.RequestQueryBuilder.getDatasetValues()); // 1a2. specify the layout to use when the list of choices appears datasetsArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 1a3. apply the adapter to the spinner datasetsSpinner.setAdapter(datasetsArrayAdapter); // 1a4. set as selected the first item on the spinner datasetsSpinner.setSelection(0); // 1b. initialize the start year spinner startYearSpinner = (Spinner) rootView.findViewById(R.id.fcd_s_start_year); // 1b1. create an ArrayAdapter using the start years and a default spinner layout ArrayAdapter<Integer> yearsArrayAdapter = new ArrayAdapter<Integer>( getActivity(), android.R.layout.simple_spinner_item, ArrayUtils.toObject(WorldBankJSONUtils.getDatasetYearsAsString())); // 1b2. specify the layout to use when the list of choices appears yearsArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 1b3. apply the adapter to the spinner startYearSpinner.setAdapter(yearsArrayAdapter); // 1b4. set as selected the first item on the spinner startYearSpinner.setSelection(0); // 1c. initialize the end year spinner endYearSpinner = (Spinner) rootView.findViewById(R.id.fcd_s_end_year); // 1c1. create an ArrayAdapter using the end years and a default spinner layout // 1c2. specify the layout to use when the list of choices appears // 1c3. apply the adapter to the spinner endYearSpinner.setAdapter(yearsArrayAdapter); // 1c4. set as selected the first item on the spinner endYearSpinner.setSelection(0); // 1d. initialize the search fab FloatingActionButton searchFloatingActionButton = (FloatingActionButton) rootView .findViewById(R.id.fcd_fab_search); // 1d1. when the fab is touched // begin searchFloatingActionButton.setOnClickListener searchFloatingActionButton.setOnClickListener( // begin new View.OnClickListener new View.OnClickListener() { @Override // begin onClick public void onClick(View view) { // 1d1a. validate the spinner choices and act accordingly validateChoicesAndAct(); } // end onClick } // end new View.OnClickListener ); // end searchFloatingActionButton.setOnClickListener // 1e. set the bar title to be the name of the app ((AppCompatActivity) (getActivity())).getSupportActionBar().setTitle(R.string.app_name); }
From source file:com.arantius.tivocommander.Upcoming.java
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final JsonNode show = showItemFromListPosition(position); final ArrayList<String> choices = new ArrayList<String>(); if (show.has("recordingForOfferId")) { choices.add("Don't Record"); } else {// w w w . j a va 2 s . c o m choices.add("Record"); } ArrayAdapter<String> choicesAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, choices); DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int position) { final String action = choices.get(position); if ("Record".equals(action)) { Intent intent = new Intent(getBaseContext(), SubscribeOffer.class); intent.putExtra("offerId", show.path("offerId").asText()); intent.putExtra("contentId", show.path("contentId").asText()); startActivityForResult(intent, 1); } else if ("Don't Record".equals(action)) { Upcoming.this.setProgressBarIndeterminateVisibility(true); final String recordingId = show.path("recordingForOfferId").path(0).path("recordingId") .asText(); MindRpc.addRequest(new RecordingUpdate(recordingId, "cancelled"), new MindRpcResponseListener() { public void onResponse(MindRpcResponse response) { // Refresh the whole thing, to remove the check. // (Lazy and slow, but it works.) startActivity(getIntent()); finish(); } }); } } }; Builder dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setTitle("Operation?"); dialogBuilder.setAdapter(choicesAdapter, onClickListener); dialogBuilder.create().show(); return true; }
From source file:com.max2idea.android.fwknop.Fwknop.java
private void setIPs() { String[] arraySpinner = { "Source IP", "", "" }; if (this.localIP != null && !this.localIP.equals("")) { Log.v("setter", this.localIP); arraySpinner[1] = this.localIP; } else {/*from w ww. j a v a2 s.c o m*/ sendHandlerMessage(handler, LOCALIP_NOTRESOLVED); return; } if (this.externalIP != null && !this.externalIP.equals("")) { arraySpinner[2] = this.externalIP; Log.v("setter", this.externalIP); } else { sendHandlerMessage(handler, EXTIP_NOTRESOLVED); } ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arraySpinner); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); this.mAllowip.setAdapter(adapter1); this.mAllowip.invalidate(); }
From source file:com.sunho.nating.fragments.DetailPlaceFragment.java
private void bindFragment(View parent) { Bundle args = getArguments();/*from w w w. j a v a 2s. c om*/ if (args == null) { return; } ImageView image = (ImageView) parent.findViewById(R.id.image); image.setImageResource(args.getInt(ARG_RESOURCE_ID)); TextView title = (TextView) parent.findViewById(R.id.title); title.setText(args.getString(ARG_TITLE)); listView = (ListView) parent.findViewById(R.id.list); sp1 = (Spinner) parent.findViewById(R.id.spinner1); sp2 = (Spinner) parent.findViewById(R.id.spinner2); sp3 = (Spinner) parent.findViewById(R.id.spinner3); final String[] sp1_data = getResources().getStringArray(R.array.areaCode_1); ArrayAdapter<String> sp1_adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, sp1_data); sp1.setAdapter(sp1_adapter); //First Adapter firstPosition = 0; final String[] sp2_data = getResources().getStringArray(R.array.sigunguCode_1); ArrayAdapter<String> sp2_adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, sp2_data); sp2.setAdapter(sp2_adapter); sp2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { secondePosition = position; switch (position) { case 0: sp3_data = getResources().getStringArray(R.array.dongCode_1_1); break; case 1: sp3_data = getResources().getStringArray(R.array.dongCode_1_2); break; case 2: sp3_data = getResources().getStringArray(R.array.dongCode_1_3); break; case 3: sp3_data = getResources().getStringArray(R.array.dongCode_1_4); break; case 4: sp3_data = getResources().getStringArray(R.array.dongCode_1_5); break; case 5: sp3_data = getResources().getStringArray(R.array.dongCode_1_6); break; case 6: sp3_data = getResources().getStringArray(R.array.dongCode_1_7); break; case 7: sp3_data = getResources().getStringArray(R.array.dongCode_1_8); break; case 8: sp3_data = getResources().getStringArray(R.array.dongCode_1_9); break; case 9: sp3_data = getResources().getStringArray(R.array.dongCode_1_10); break; case 10: sp3_data = getResources().getStringArray(R.array.dongCode_1_11); break; case 11: sp3_data = getResources().getStringArray(R.array.dongCode_1_12); break; case 12: sp3_data = getResources().getStringArray(R.array.dongCode_1_13); break; case 13: sp3_data = getResources().getStringArray(R.array.dongCode_1_14); break; case 14: sp3_data = getResources().getStringArray(R.array.dongCode_1_15); break; case 15: sp3_data = getResources().getStringArray(R.array.dongCode_1_16); break; case 16: sp3_data = getResources().getStringArray(R.array.dongCode_1_17); break; case 17: sp3_data = getResources().getStringArray(R.array.dongCode_1_18); break; case 18: sp3_data = getResources().getStringArray(R.array.dongCode_1_19); break; case 19: sp3_data = getResources().getStringArray(R.array.dongCode_1_20); break; case 20: sp3_data = getResources().getStringArray(R.array.dongCode_1_21); break; case 21: sp3_data = getResources().getStringArray(R.array.dongCode_1_22); break; case 22: sp3_data = getResources().getStringArray(R.array.dongCode_1_23); break; case 23: sp3_data = getResources().getStringArray(R.array.dongCode_1_24); break; case 24: sp3_data = getResources().getStringArray(R.array.dongCode_1_25); break; default: break; } ArrayAdapter<String> sp3_adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, sp3_data); sp3.setAdapter(sp3_adapter); sp3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { result = sp2_data[secondePosition] + " " + sp3_data[position]; Log.d("Theme", "Selected Location : " + result); totalURL = makeURL(1, result); placeList.clear(); pageCount = 1; adapter.isEndFalse(); adapter.resetServerListSize(0); adapter.notifyDataSetChanged(); new GetDataTask().execute(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); listView.setDividerHeight(0); adapter = new CustomListAdapter(MainActivity.mActivity, placeList) { @Override public View getDataRow(int position, View convertView, ViewGroup parent) { return convertView; } }; listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(MainActivity.mContext, placeList.get(position).getOldAddress(), 0).show(); moveFragment(position); } }); listView.setOnScrollListener(new EndlessScrollListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { super.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); //lastListitem = (totalItemCount - 1 > 0) && (firstVisibleItem + visibleItemCount >= totalItemCount - 1); } @Override public void onLoadMore(int page, int totalItemsCount) { // Triggered only when new data needs to be appended to the list // Add whatever code is needed to append new items to your AdapterView Log.d(TAG, "==ListView Information=="); Log.d(TAG, "PageNumber : " + page); Log.d(TAG, "TotalCount : " + totalItemsCount); Log.d(TAG, "adpaterCount : " + adapter.getCount()); Log.d(TAG, "========================"); new GetDataTask().execute(); } }); }
From source file:com.jdom.get.stuff.done.android.AndroidApplicationContextFactory.java
public void displayCollectionOfItemsAsRadioButtonGroup(String message, Collection<String> collection, String initialSelection, final RunnableWithResults<String> callback) { final String[] array = collection.toArray(new String[collection.size()]); int selectedItemIndex = -1; if (initialSelection != null) { for (int i = 0; i < array.length; i++) { if (array[i].equals(initialSelection)) { selectedItemIndex = i;//from w w w. ja v a 2 s .c o m } } } final List<String> selectedItems = new ArrayList<String>(); if (initialSelection != null) { selectedItems.add(initialSelection); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_single_choice, array); AlertDialog.Builder builder = new AlertDialog.Builder(activity); if (!StringUtils.isEmpty(message)) { builder.setTitle(message); } builder.setPositiveButton(OK_BUTTON_TEXT, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (!selectedItems.isEmpty()) { callback.callback(selectedItems.iterator().next()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }).setSingleChoiceItems(arrayAdapter, selectedItemIndex, new OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { String value = array[arg1]; selectedItems.clear(); selectedItems.add(value); } }).show(); }
From source file:com.ardnezar.lookapp.ConnectActivity.java
@Override public void onResume() { super.onResume(); String room = sharedPref.getString(keyprefRoom, ""); roomEditText.setText(room);// w w w .j av a 2 s . c om roomList = new ArrayList<String>(); String roomListJson = sharedPref.getString(keyprefRoomList, null); if (roomListJson != null) { try { JSONArray jsonArray = new JSONArray(roomListJson); for (int i = 0; i < jsonArray.length(); i++) { roomList.add(jsonArray.get(i).toString()); } } catch (JSONException e) { Log.e(TAG, "Failed to load room list: " + e.toString()); } } adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, roomList); roomListView.setAdapter(adapter); if (adapter.getCount() > 0) { roomListView.requestFocus(); roomListView.setItemChecked(0, true); } }
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);//from w w w.j a v a 2s. c o m 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:li.klass.fhem.adapter.devices.genericui.AvailableTargetStatesDialogUtil.java
public static <D extends FhemDevice<D>> TypeHandler<D> handlerForSelectedOption(D device, Context context, final String option, final TargetStateSelectedCallback callback) { SetList setList = device.getSetList(); final SetListValue setListValue = setList.get(option); final DeviceStateRequiringAdditionalInformation specialDeviceState = DeviceStateRequiringAdditionalInformation .deviceStateForFHEM(option); if (setListValue instanceof SetListSliderValue) { final SetListSliderValue sliderValue = (SetListSliderValue) setListValue; return new TypeHandler<D>() { private int dimProgress = 0; @Override/*from w w w .j ava2 s .co m*/ public View getContentViewFor(Context context, D device) { TableLayout tableLayout = new TableLayout(context); int initialProgress = 0; if (device instanceof DimmableDevice) { initialProgress = ((DimmableDevice) device).getDimPosition(); } tableLayout.addView(new DeviceDimActionRowFullWidth<D>(initialProgress, sliderValue.getStart(), sliderValue.getStep(), sliderValue.getStop(), null, R.layout.device_detail_seekbarrow_full_width) { @Override public void onStopDim(Context context, D device, int progress) { dimProgress = progress; } @Override public String toDimUpdateText(D device, int progress) { return null; } }.createRow(LayoutInflater.from(context), device)); return tableLayout; } @Override public boolean onPositiveButtonClick(View view, Context context, D device) { callback.onTargetStateSelected(option, "" + dimProgress, device, context); return true; } }; } else if (setListValue instanceof SetListGroupValue) { final SetListGroupValue groupValue = (SetListGroupValue) setListValue; final List<String> groupStates = groupValue.getGroupStates(); return new TypeHandler<D>() { @Override public View getContentViewFor(final Context context, final D device) { ListView listView = new ListView(context); listView.setAdapter( new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, groupStates)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { String selection = groupStates.get(position); callback.onTargetStateSelected(option, selection, device, context); dialog.dismiss(); } }); return listView; } @Override boolean requiresPositiveButton() { return false; } }; } else if (specialDeviceState != null) { return new TypeHandler<D>() { private EditText editText; @Override public View getContentViewFor(Context context, D device) { editText = new EditText(context); return editText; } @Override public boolean onPositiveButtonClick(View view, Context context, D device) { Editable value = editText.getText(); String text = value == null ? "" : value.toString(); if (isValidAdditionalInformationValue(text, specialDeviceState)) { callback.onTargetStateSelected(option, text, device, context); return true; } else { DialogUtil.showAlertDialog(context, R.string.error, R.string.invalidInput); return false; } } }; } else { callback.onTargetStateSelected(option, null, device, context); return null; } }
From source file:com.devwang.logcabin.LogCabinMainActivity.java
@SuppressLint("NewApi") @Override//from www .j a v a 2 s. c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (D) Log.e(TAG, "+++ ON CREATE +++"); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // isFirstInstallApp(); diyTitle(); viewInit(); mTitleLeft.setText(R.string.app_name);// soundMediaPlayer = new MediaPlayer();// autoeditTextView.setAdapter( new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, autoedit_items)); // appid http://open.voicecloud.cn/ appid:54202a57 rd = new RecognizerDialog(this, getString(R.string.str_devwang_voice_key_appid)); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); isSupportBT(); isNonConnBt(); mLogCabinInfo = new LogCabinInfo("", "", "", "", "", "", "", "", "", "", ""); }
From source file:com.facebook.samples.sessionlogin.LoginUsingActivityActivity.java
public void showDialog() { final Dialog dialog = new Dialog(LoginUsingActivityActivity.this); dialog.setContentView(R.layout.list_view_contact); dialog.setTitle("Pic Number"); ListView listView = (ListView) dialog.findViewById(R.id.lc_contacts); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner_row_view, list);/*w w w .j a v a 2 s . c om*/ listView.setAdapter(adapter); dialog.show(); /*DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); dialog.getWindow().setLayout(metrics.heightPixels, metrics.widthPixels);*/ }