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:com.mifos.mifosxdroid.dialogfragments.LoanAccountDisbursement.java
private void inflatePaymentTypeSpinner() { App.apiManager.getLoanTemplate(loanAccountNumber, new Callback<Response>() { @Override//from w w w . j av a2 s . com public void success(Response result, Response response) { final ArrayList<PaymentTypeOptions> paymentOption = new ArrayList<PaymentTypeOptions>(); final ArrayList<String> paymentNames = new ArrayList<String>(); BufferedReader reader = null; StringBuilder sb = new StringBuilder(); String line; try { reader = new BufferedReader(new InputStreamReader(result.getBody().in())); while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("paymentTypeOptions")) { JSONArray paymentOptions = obj.getJSONArray("paymentTypeOptions"); for (int i = 0; i < paymentOptions.length(); i++) { JSONObject paymentObject = paymentOptions.getJSONObject(i); PaymentTypeOptions payment = new PaymentTypeOptions(); payment.setId(paymentObject.optInt("id")); payment.setName(paymentObject.optString("name")); paymentOption.add(payment); paymentNames.add(paymentObject.optString("name")); paymentNameIdHashMap.put(payment.getName(), payment.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } ArrayAdapter<String> paymentAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, paymentNames); paymentAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_payment_type.setAdapter(paymentAdapter); sp_payment_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { paymentTypeId = paymentNameIdHashMap.get(paymentNames.get(i)); Log.d("paymentId " + paymentNames.get(i), String.valueOf(paymentTypeId)); if (paymentTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_payment), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } @Override public void failure(RetrofitError retrofitError) { Log.d(LOG_TAG, retrofitError.getLocalizedMessage()); } }); }
From source file:com.mifos.mifosxdroid.dialogfragments.loanaccountdisbursement.LoanAccountDisbursement.java
@Override public void showLoanTemplate(ResponseBody result) { final ArrayList<PaymentTypeOptions> paymentOption = new ArrayList<PaymentTypeOptions>(); final ArrayList<String> paymentNames = new ArrayList<String>(); BufferedReader reader = null; StringBuilder sb = new StringBuilder(); String line;/*from w w w . jav a 2 s . c o m*/ try { reader = new BufferedReader(new InputStreamReader(result.byteStream())); while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("paymentTypeOptions")) { JSONArray paymentOptions = obj.getJSONArray("paymentTypeOptions"); for (int i = 0; i < paymentOptions.length(); i++) { JSONObject paymentObject = paymentOptions.getJSONObject(i); PaymentTypeOptions payment = new PaymentTypeOptions(); payment.setId(paymentObject.optInt("id")); payment.setName(paymentObject.optString("name")); paymentOption.add(payment); paymentNames.add(paymentObject.optString("name")); paymentNameIdHashMap.put(payment.getName(), payment.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } ArrayAdapter<String> paymentAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, paymentNames); paymentAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_payment_type.setAdapter(paymentAdapter); sp_payment_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { paymentTypeId = paymentNameIdHashMap.get(paymentNames.get(i)); Log.d("paymentId " + paymentNames.get(i), String.valueOf(paymentTypeId)); if (paymentTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_payment), Toast.LENGTH_SHORT) .show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.micabyte.android.app.BaseFragment.java
@SuppressWarnings("ConstantConditions") protected Spinner setSpinner(int resId, int arrId) { final Spinner s = (Spinner) getView().findViewById(resId); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( getActivity().getApplicationContext(), arrId, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(adapter);/* w w w. ja va 2s. c o m*/ return s; }
From source file:com.renard.ocr.documents.creation.visualisation.LayoutQuestionDialog.java
@NonNull @Override/*w w w . jav a2 s. co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { getAnalytics().sendScreenView(SCREEN_NAME); final Context context = getContext(); mLayout = null; Pair<String, String> language = PreferencesUtils.getOCRLanguage(context); final OcrLanguage.InstallStatus installStatus = OcrLanguageDataStore.isLanguageInstalled(language.first, context); if (!installStatus.isInstalled()) { final String defaultLanguage = context.getString(R.string.default_ocr_language); final String defaultLanguageDisplay = context.getString(R.string.default_ocr_display_language); language = Pair.create(defaultLanguage, defaultLanguageDisplay); } mLanguage = language.first; AlertDialog.Builder builder; builder = new AlertDialog.Builder(context); builder.setCancelable(false); View layout = View.inflate(context, R.layout.dialog_layout_question, null); builder.setView(layout); final ViewFlipper titleViewFlipper = (ViewFlipper) layout.findViewById(R.id.layout_title); final ImageView columnLayout = (ImageView) layout.findViewById(R.id.column_layout); final ImageView pageLayout = (ImageView) layout.findViewById(R.id.page_layout); final ImageSwitcher fairy = (ImageSwitcher) layout.findViewById(R.id.fairy_layout); fairy.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { return new ImageView(context); } }); fairy.setImageResource(R.drawable.fairy_looks_center); fairy.setInAnimation(context, android.R.anim.fade_in); fairy.setOutAnimation(context, android.R.anim.fade_out); final int color = context.getResources().getColor(R.color.progress_color); final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.LIGHTEN); columnLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mLayout != LayoutKind.COMPLEX) { fairy.setImageResource(R.drawable.fairy_looks_left); titleViewFlipper.setDisplayedChild(2); columnLayout.setColorFilter(colorFilter); pageLayout.clearColorFilter(); mLayout = LayoutKind.COMPLEX; } } }); pageLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mLayout != LayoutKind.SIMPLE) { mLayout = LayoutKind.SIMPLE; titleViewFlipper.setDisplayedChild(1); fairy.setImageResource(R.drawable.fairy_looks_right); pageLayout.setColorFilter(colorFilter); columnLayout.clearColorFilter(); } } }); final Spinner langButton = (Spinner) layout.findViewById(R.id.button_language); List<OcrLanguage> installedLanguages = OcrLanguageDataStore.getInstalledOCRLanguages(context); // actual values uses by tesseract final ArrayAdapter<OcrLanguage> adapter = new ArrayAdapter<>(context, R.layout.language_spinner_item, installedLanguages); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); langButton.setAdapter(adapter); for (int i = 0; i < installedLanguages.size(); i++) { OcrLanguage lang = installedLanguages.get(i); if (lang.getValue().equals(language.first)) { langButton.setSelection(i, false); break; } } langButton.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { final OcrLanguage item = adapter.getItem(position); mLanguage = item.getValue(); PreferencesUtils.saveOCRLanguage(context, item); getAnalytics().sendOcrLanguageChanged(item); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); builder.setPositiveButton(R.string.start_scan, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (mLayout == null) { mLayout = LayoutKind.SIMPLE; } LayoutChoseListener listener = (LayoutChoseListener) getActivity(); listener.onLayoutChosen(mLayout, mLanguage); getAnalytics().sendOcrStarted(mLanguage, mLayout); dialog.dismiss(); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { getActivity().finish(); dialog.dismiss(); getAnalytics().sendLayoutDialogCancelled(); } }); return builder.create(); }
From source file:com.google.firebase.samples.apps.mlkit.LivePreviewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); setContentView(R.layout.activity_live_preview); preview = (CameraSourcePreview) findViewById(R.id.firePreview); if (preview == null) { Log.d(TAG, "Preview is null"); }/*from w w w. j a va2 s . com*/ graphicOverlay = (GraphicOverlay) findViewById(R.id.fireFaceOverlay); if (graphicOverlay == null) { Log.d(TAG, "graphicOverlay is null"); } Spinner spinner = (Spinner) findViewById(R.id.spinner); List<String> options = new ArrayList<>(); options.add(FACE_DETECTION); options.add(TEXT_DETECTION); options.add(BARCODE_DETECTION); options.add(IMAGE_LABEL_DETECTION); options.add(CLASSIFICATION); // Creating adapter for spinner ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, R.layout.spinner_style, options); // Drop down layout style - list view with radio button dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // attaching data adapter to spinner spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener(this); ToggleButton facingSwitch = (ToggleButton) findViewById(R.id.facingswitch); facingSwitch.setOnCheckedChangeListener(this); if (allPermissionsGranted()) { createCameraSource(selectedModel); } else { getRuntimePermissions(); } }
From source file:com.mifos.mifosxdroid.dialogfragments.chargedialog.ChargeDialogFragment.java
@Override public void showAllChargesV2(ResponseBody result) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return;//from w w w.j a v a 2s .c om 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.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.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) { } }); }
From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java
@Override public void onViewCreated(final View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); mCurrentDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_current_directory); mNothingInDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_nothing_in_directory); mPrimaryVolumeNameTextView = (TextView) rootView.findViewById(R.id.textview_primary_volume_name); // Set onClickListener for the primary volume Button openPictureButton = (Button) rootView.findViewById(R.id.button_open_directory_primary_volume); openPictureButton.setOnClickListener(new View.OnClickListener() { @Override//from www.j av a 2s. c o m public void onClick(View view) { String selected = mDirectoriesSpinner.getSelectedItem().toString(); String directoryName = getDirectoryName(selected); StorageVolume storageVolume = mStorageManager.getPrimaryStorageVolume(); Intent intent = storageVolume.createAccessIntent(directoryName); startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE); } }); // Set onClickListener for the external volumes if exists List<StorageVolume> storageVolumes = mStorageManager.getStorageVolumes(); LinearLayout containerVolumes = (LinearLayout) mActivity.findViewById(R.id.container_volumes); for (final StorageVolume volume : storageVolumes) { String volumeDescription = volume.getDescription(mActivity); if (volume.isPrimary()) { // Primary volume area is already added... if (volumeDescription != null) { // ...but with a default name: set it to the real name when available. mPrimaryVolumeNameTextView.setText(volumeDescription); } continue; } LinearLayout volumeArea = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.volume_entry, containerVolumes); TextView volumeName = (TextView) volumeArea.findViewById(R.id.textview_volume_name); volumeName.setText(volumeDescription); Button button = (Button) volumeArea.findViewById(R.id.button_open_directory); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String selected = mDirectoriesSpinner.getSelectedItem().toString(); String directoryName = getDirectoryName(selected); Intent intent = volume.createAccessIntent(directoryName); startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE); } }); } RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_directory_entries); if (savedInstanceState != null) { mDirectoryEntries = savedInstanceState.getParcelableArrayList(DIRECTORY_ENTRIES_KEY); mCurrentDirectoryTextView.setText(savedInstanceState.getString(SELECTED_DIRECTORY_KEY)); mAdapter = new DirectoryEntryAdapter(mDirectoryEntries); if (mAdapter.getItemCount() == 0) { mNothingInDirectoryTextView.setVisibility(View.VISIBLE); } } else { mDirectoryEntries = new ArrayList<>(); mAdapter = new DirectoryEntryAdapter(); } recyclerView.setAdapter(mAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); mDirectoriesSpinner = (Spinner) rootView.findViewById(R.id.spinner_directories); ArrayAdapter<CharSequence> directoriesAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.directories, android.R.layout.simple_spinner_item); directoriesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDirectoriesSpinner.setAdapter(directoriesAdapter); }
From source file:com.javierc.albuquerquenow.TransitMap.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up the action bar to show a dropdown list. actionBar = getActionBar();/* w w w . j a v a 2 s . co m*/ actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); final String[] dropdownValues = getResources().getStringArray(R.array.dropdown); // Specify a SpinnerAdapter to populate the dropdown list. ArrayAdapter<String> adapter = new ArrayAdapter<String>(actionBar.getThemedContext(), android.R.layout.simple_spinner_item, android.R.id.text1, dropdownValues); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Set up the dropdown list navigation in the action bar. actionBar.setListNavigationCallbacks(adapter, this); googlemap.getUiSettings().setRotateGesturesEnabled(false); }
From source file:com.armtimes.dialogs.DialogSettings.java
/** * This function initialize News Preview Font Size Spinner and * it's adapter./*from w w w . j a va 2s .c o m*/ * * @param settingsView Settings view with controllers. */ private void initFontSizeStuff(final View settingsView) { Spinner fontSizeSpinner = (Spinner) settingsView.findViewById(R.id.spinnerFontSize); // Initialize Adapter ArrayAdapter fontSizeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.font_size_array, android.R.layout.simple_spinner_item); fontSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fontSizeSpinner.setAdapter(fontSizeAdapter); int selectedItem = 0; switch (getTextFontSize(getActivity())) { case android.R.style.TextAppearance_Medium: selectedItem = 1; break; case android.R.style.TextAppearance_Large: selectedItem = 2; break; } fontSizeSpinner.setSelection(selectedItem); fontSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setTextFontSize(position == 1 ? android.R.style.TextAppearance_Medium : position == 2 ? android.R.style.TextAppearance_Large : android.R.style.TextAppearance_Small); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.teleca.jamendo.activity.SearchActivity.java
/** Called when the activity is first created. */ @SuppressWarnings("unchecked") @Override/*from w w w .j av a 2 s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.search); mSearchSpinner = (Spinner) findViewById(R.id.SearchSpinner); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.search_modes, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSearchSpinner.setAdapter(adapter); mSearchButton = (Button) findViewById(R.id.SearchButton); mSearchButton.setOnClickListener(mSearchButtonListener); mSearchEditText = (EditText) findViewById(R.id.SearchEditText); mSearchListView = (ListView) findViewById(R.id.SearchListView); mViewFlipper = (ViewFlipper) findViewById(R.id.SearchViewFlipper); if (mSearchListView.getCount() == 0) { mViewFlipper.setDisplayedChild(2); // search list hint } mGestureOverlayView = (GestureOverlayView) findViewById(R.id.gestures); mGestureOverlayView .addOnGesturePerformedListener(JamendoApplication.getInstance().getPlayerGestureHandler()); }