Java Code Examples for android.widget.ArrayAdapter#getPosition()
The following examples show how to use
android.widget.ArrayAdapter#getPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TGBrowserView.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings("unchecked") public void refreshCollections(boolean forceDefaults) { ArrayAdapter<TGSelectableItem> arrayAdapter = new ArrayAdapter<TGSelectableItem>(findActivity(), android.R.layout.simple_spinner_item, createCollectionValues()); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); TGBrowserCollection selectedCollection = (forceDefaults ? TGBrowserManager.getInstance(this.findContext()).getDefaultCollection() : this.findCurrentCollection()); TGSelectableItem selectedItem = new TGSelectableItem(selectedCollection, null); Integer selectedItemPosition = arrayAdapter.getPosition(selectedItem); Spinner spinner = (Spinner) this.findViewById(R.id.browser_collections); OnItemSelectedListener listener = spinner.getOnItemSelectedListener(); spinner.setOnItemSelectedListener(null); if(!this.isSameCollection(arrayAdapter, (ArrayAdapter<TGSelectableItem>) spinner.getAdapter())) { spinner.setAdapter(arrayAdapter); } spinner.setOnItemSelectedListener(listener); if( spinner.getSelectedItemPosition() != selectedItemPosition ) { spinner.setSelection(selectedItemPosition, false); } }
Example 2
Source File: SettingsActivity.java From WaniKani-for-Android with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") private void showReminderNotificationIntervalDialog() { final ArrayAdapter<Integer> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_single_choice); adapter.addAll(getReminderNotificationIntervals()); int currentSelection = adapter.getPosition((int) (PrefManager.getReminderNotificationInterval() / 60000)); new AlertDialog.Builder(this) .setTitle(getString(R.string.minutes)) .setSingleChoiceItems(adapter, currentSelection, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int position) { PrefManager.setReminderNotificationInterval(adapter.getItem(position) * 60000); } }) .setPositiveButton(R.string.ok, null) .create().show(); }
Example 3
Source File: ExtraUserPropertyLayout.java From kakao-android-sdk-standalone with Apache License 2.0 | 6 votes |
void showProperties(final Map<String, String> properties) { final String nameValue = properties.get(NAME_KEY); if (nameValue != null) name.setText(nameValue); final String ageValue = properties.get(AGE_KEY); if (ageValue != null) age.setText(ageValue); final String genderValue = properties.get(GENDER_KEY); if (genderValue != null) { ArrayAdapter<String> myAdap = (ArrayAdapter<String>) gender.getAdapter(); //cast to an ArrayAdapter int spinnerPosition = myAdap.getPosition(genderValue); gender.setSelection(spinnerPosition); } }
Example 4
Source File: ProfileSetting.java From XERUNG with Apache License 2.0 | 5 votes |
private void setBloodAdapter() { final String[] choices = {"A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"}; ArrayAdapter<String> badapter = new ArrayAdapter<String>(ProfileSetting.this, android.R.layout.simple_spinner_item, choices); badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBloodGroup.setAdapter(badapter); try { if (!bloodGroup.equals(null) && !bloodGroup.equals("0")) { int spinnerPosition = badapter.getPosition(bloodGroup); spBloodGroup.setSelection(spinnerPosition + 1); } } catch (Exception e) { // TODO: handle exception } }
Example 5
Source File: ProfileSetting.java From XERUNG with Apache License 2.0 | 5 votes |
private void setBloodAdapter() { final String[] choices = {"A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"}; ArrayAdapter<String> badapter = new ArrayAdapter<String>(ProfileSetting.this, android.R.layout.simple_spinner_item, choices); badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBloodGroup.setAdapter(badapter); try { if (!bloodGroup.equals(null) && !bloodGroup.equals("0")) { int spinnerPosition = badapter.getPosition(bloodGroup); spBloodGroup.setSelection(spinnerPosition + 1); } } catch (Exception e) { // TODO: handle exception } }
Example 6
Source File: AccountBillingInfoFragment.java From arcusandroid with Apache License 2.0 | 4 votes |
private void setSpinnerByValue(Spinner spinner, String value){ ArrayAdapter<CharSequence> arrayAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter(); int spinnerPosition = arrayAdapter.getPosition(value); spinner.setSelection(spinnerPosition); }
Example 7
Source File: PlaceAccountBillingInfoFragment.java From arcusandroid with Apache License 2.0 | 4 votes |
private void setSpinnerByValue(Spinner spinner, String value){ ArrayAdapter<CharSequence> arrayAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter(); int spinnerPosition = arrayAdapter.getPosition(value); spinner.setSelection(spinnerPosition); }
Example 8
Source File: CreateConnectionFragment.java From FireFiles with Apache License 2.0 | 4 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getActivity(); final AlertDialog.Builder builder = new AlertDialog.Builder(context); final LayoutInflater dialogInflater = getActivity().getLayoutInflater(); final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false); name = (AppCompatEditText) view.findViewById(R.id.name); host = (AppCompatEditText) view.findViewById(R.id.host); port = (AppCompatEditText) view.findViewById(R.id.port); path = (AppCompatEditText) view.findViewById(R.id.path); hostContainer = view.findViewById(R.id.hostContainer); pathContainer = view.findViewById(R.id.pathContainer); username = (AppCompatEditText) view.findViewById(R.id.username); usernameContainer = view.findViewById(R.id.usernameContainer); password = (AppCompatEditText) view.findViewById(R.id.password); passwordContainer = view.findViewById(R.id.passwordContainer); scheme = (AppCompatSpinner) view.findViewById(R.id.scheme); anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous); anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE); passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE); } }); if(connection_id != 0){ NetworkConnection connection = NetworkConnection.fromConnectionId(getActivity(), connection_id); ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter(); int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase()); scheme.setSelection(spinnerPosition); name.setText(connection.getName()); host.setText(connection.getHost()); port.setText(Integer.toString(connection.getPort())); path.setText(connection.getPath()); username.setText(connection.getUserName()); password.setText(connection.getPassword()); anonymous.setChecked(connection.isAnonymousLogin()); if(SERVER.equals(connection.getType())){ hostContainer.setVisibility(View.GONE); pathContainer.setVisibility(View.VISIBLE); } } builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection"); builder.setView(view); builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final BaseActivity activity = (BaseActivity) getActivity(); NetworkConnection networkConnection = getNetworkConnection(); if(validate(networkConnection)){ new CreateConnectionTask(activity, networkConnection).executeOnExecutor( ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY)); } } }); builder.setNegativeButton(android.R.string.cancel, null); return builder.create(); }
Example 9
Source File: CreateConnectionFragment.java From FireFiles with Apache License 2.0 | 4 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getActivity(); final AlertDialog.Builder builder = new AlertDialog.Builder(context); final LayoutInflater dialogInflater = getActivity().getLayoutInflater(); final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false); name = (AppCompatEditText) view.findViewById(R.id.name); host = (AppCompatEditText) view.findViewById(R.id.host); port = (AppCompatEditText) view.findViewById(R.id.port); path = (AppCompatEditText) view.findViewById(R.id.path); hostContainer = view.findViewById(R.id.hostContainer); pathContainer = view.findViewById(R.id.pathContainer); username = (AppCompatEditText) view.findViewById(R.id.username); usernameContainer = view.findViewById(R.id.usernameContainer); password = (AppCompatEditText) view.findViewById(R.id.password); passwordContainer = view.findViewById(R.id.passwordContainer); scheme = (AppCompatSpinner) view.findViewById(R.id.scheme); anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous); anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE); passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE); } }); if(connection_id != 0){ NetworkConnection connection = NetworkConnection.fromConnectionId(getActivity(), connection_id); ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter(); int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase()); scheme.setSelection(spinnerPosition); name.setText(connection.getName()); host.setText(connection.getHost()); port.setText(Integer.toString(connection.getPort())); path.setText(connection.getPath()); username.setText(connection.getUserName()); password.setText(connection.getPassword()); anonymous.setChecked(connection.isAnonymousLogin()); if(SERVER.equals(connection.getType())){ hostContainer.setVisibility(View.GONE); pathContainer.setVisibility(View.VISIBLE); } } builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection"); builder.setView(view); builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final BaseActivity activity = (BaseActivity) getActivity(); NetworkConnection networkConnection = getNetworkConnection(); if(validate(networkConnection)){ new CreateConnectionTask(activity, networkConnection).executeOnExecutor( ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY)); } } }); builder.setNegativeButton(android.R.string.cancel, null); return builder.create(); }
Example 10
Source File: CreateConnectionFragment.java From FireFiles with Apache License 2.0 | 4 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getActivity(); final AlertDialog.Builder builder = new AlertDialog.Builder(context); final LayoutInflater dialogInflater = getActivity().getLayoutInflater(); final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false); name = (AppCompatEditText) view.findViewById(R.id.name); host = (AppCompatEditText) view.findViewById(R.id.host); port = (AppCompatEditText) view.findViewById(R.id.port); path = (AppCompatEditText) view.findViewById(R.id.path); hostContainer = view.findViewById(R.id.hostContainer); pathContainer = view.findViewById(R.id.pathContainer); username = (AppCompatEditText) view.findViewById(R.id.username); usernameContainer = view.findViewById(R.id.usernameContainer); password = (AppCompatEditText) view.findViewById(R.id.password); passwordContainer = view.findViewById(R.id.passwordContainer); scheme = (AppCompatSpinner) view.findViewById(R.id.scheme); anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous); anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE); passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE); } }); if(connection_id != 0){ NetworkConnection connection = NetworkConnection.fromConnectionId(getActivity(), connection_id); ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter(); int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase()); scheme.setSelection(spinnerPosition); name.setText(connection.getName()); host.setText(connection.getHost()); port.setText(Integer.toString(connection.getPort())); path.setText(connection.getPath()); username.setText(connection.getUserName()); password.setText(connection.getPassword()); anonymous.setChecked(connection.isAnonymousLogin()); if(SERVER.equals(connection.getType())){ hostContainer.setVisibility(View.GONE); pathContainer.setVisibility(View.VISIBLE); } } builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection"); builder.setView(view); builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final BaseActivity activity = (BaseActivity) getActivity(); NetworkConnection networkConnection = getNetworkConnection(); if(validate(networkConnection)){ new CreateConnectionTask(activity, networkConnection).executeOnExecutor( ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY)); } } }); builder.setNegativeButton(android.R.string.cancel, null); return builder.create(); }
Example 11
Source File: ModelSelectorFragment.java From evercam-android with GNU Affero General Public License v3.0 | 4 votes |
public void buildVendorSpinner(ArrayList<Vendor> vendorList, String selectedVendor) { if (vendorMap == null) { vendorMap = new TreeMap<>(); } if (vendorMapIdAsKey == null) { vendorMapIdAsKey = new TreeMap<>(); } if (vendorList != null) { for (Vendor vendor : vendorList) { try { vendorMap.put(vendor.getName(), vendor.getId()); vendorMapIdAsKey.put(vendor.getId(), vendor.getName()); } catch (EvercamException e) { Log.e(TAG, e.toString()); } } } Set<String> set = vendorMap.keySet(); String[] vendorArray = Commons.joinStringArray(new String[]{getResources().getString(R .string.select_vendor)}, set.toArray(new String[0])); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, vendorArray); spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner); int selectedPosition = 0; if (isAddActivity()) { if (getAddActivity().isFromDiscoverAndHasVendor()) { String vendorId = getAddActivity().getDiscoveredCamera().getVendor(); String vendorName = vendorMapIdAsKey.get(vendorId); selectedPosition = spinnerArrayAdapter.getPosition(vendorName); } } if (selectedVendor != null) { selectedPosition = spinnerArrayAdapter.getPosition(selectedVendor); } vendorSpinner.setAdapter(spinnerArrayAdapter); if (selectedPosition != 0) { vendorSpinner.setSelection(selectedPosition); } /* If vendor state are saved but haven't been selected */ else if (vendorSavedSelectedPosition != 0 && vendorSpinner.getCount() > 1 && vendorSavedSelectedPosition < vendorSpinner.getCount()) { vendorSpinner.setSelection(vendorSavedSelectedPosition); vendorSavedSelectedPosition = 0; //Then reset it } }
Example 12
Source File: ModelSelectorFragment.java From evercam-android with GNU Affero General Public License v3.0 | 4 votes |
public void buildModelSpinner(ArrayList<Model> modelList, String selectedModel) { if (modelMap == null) { modelMap = new TreeMap<>(); } modelMap.clear(); if (modelList == null) { modelSpinner.setEnabled(false); } else { if (modelList.size() == 0) { modelSpinner.setEnabled(false); } else { modelSpinner.setEnabled(true); for (Model model : modelList) { try { modelMap.put(model.getId(), model.getName()); } catch (EvercamException e) { Log.e(TAG, e.toString()); } } } } Collection<String> modelNameCollection = modelMap.values(); String[] fullModelArray = Commons.joinStringArray(new String[]{getResources().getString(R .string.select_model)}, modelNameCollection.toArray(new String[0])); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, fullModelArray); int defaultObjectIndex = spinnerArrayAdapter.getPosition(getString(R.string .model_default)); if (defaultObjectIndex >= 0){ String defaultObject = fullModelArray[defaultObjectIndex]; for (int i = (defaultObjectIndex - 1); i >= 0; i--) { fullModelArray[i+1] = fullModelArray[i]; } fullModelArray[1] = defaultObject; } spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner); modelSpinner.setAdapter(spinnerArrayAdapter); int selectedPosition = 0; if (selectedModel != null) { if (modelMap.get(selectedModel) != null) { String selectedModelName = modelMap.get(selectedModel); selectedPosition = spinnerArrayAdapter.getPosition(selectedModelName); } } if (selectedPosition != 0) { modelSpinner.setSelection(selectedPosition); } /* If vendor state are saved but haven't been selected */ else if (modelSavedSelectedPosition != 0 && modelSpinner.getCount() > 1 && modelSavedSelectedPosition < modelSpinner.getCount()) { modelSpinner.setSelection(modelSavedSelectedPosition); modelSavedSelectedPosition = 0; // Then reset it } else { modelSpinner.setSelection(spinnerArrayAdapter.getPosition(getString(R.string .model_default))); } }
Example 13
Source File: FieldEditorActivity.java From Field-Book with GNU General Public License v2.0 | 4 votes |
private void setSpinner(Spinner spinner, String[] data, String pref) { ArrayAdapter<String> itemsAdapter = new ArrayAdapter<>(this, R.layout.custom_spinnerlayout, data); spinner.setAdapter(itemsAdapter); int spinnerPosition = itemsAdapter.getPosition(ep.getString(pref, itemsAdapter.getItem(0))); spinner.setSelection(spinnerPosition); }
Example 14
Source File: ColumnDialog.java From Onosendai with Apache License 2.0 | 4 votes |
private void setDurationSpinner (final int mins, final ArrayAdapter<Duration> refAdapter) { final Duration duration = new Duration(mins > 0 ? mins : 0); final int pos = refAdapter.getPosition(duration); if (pos < 0) refAdapter.add(duration); // Allow for any value to have been chosen before. this.spnRefresh.setSelection(pos < 0 ? refAdapter.getPosition(duration) : pos); }
Example 15
Source File: GTwoConnectedComboView.java From geopaparazzi with GNU General Public License v3.0 | 4 votes |
/** * @param context the context to use. * @param attrs attributes. * @param parentView parent * @param label label * @param value _value * @param dataMap the map of the data. * @param constraintDescription constraints */ public GTwoConnectedComboView(Context context, AttributeSet attrs, LinearLayout parentView, String label, String value, LinkedHashMap<String, List<String>> dataMap, String constraintDescription) { super(context, attrs); this.dataMap = dataMap; if (value == null) value = ""; String[] valueSplit = value.split(SEP); String _combo1Value; String _combo2Value; if (valueSplit.length == 2) { _combo1Value = valueSplit[0]; _combo2Value = valueSplit[1]; } else { _combo1Value = ""; _combo2Value = ""; } TextView textView = new TextView(context); LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); textViewParams.setMargins(15, 25, 15, 15); textView.setLayoutParams(textViewParams); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(Compat.getColor(context, R.color.formcolor)); parentView.addView(textView); LinearLayout combosLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); combosLayout.setLayoutParams(layoutParams); combosLayout.setOrientation(LinearLayout.VERTICAL); combosLayout.setBackground(Compat.getDrawable(context, R.drawable.thin_background_frame)); parentView.addView(combosLayout); combo1Spinner = new Spinner(context); LinearLayout.LayoutParams titleSpinnerParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); titleSpinnerParams.setMargins(15, 25, 15, 15); combo1Spinner.setLayoutParams(titleSpinnerParams); Set<String> titlesSet = dataMap.keySet(); ArrayList<String> combo1Items = new ArrayList<>(titlesSet); combo1Items.add(0, ""); ArrayAdapter<String> titleListAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, combo1Items); titleListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); combo1Spinner.setAdapter(titleListAdapter); combo1Spinner.setPopupBackgroundDrawable(Compat.getDrawable(context, R.drawable.thin_background_frame)); combo1Spinner.setBackground(Compat.getDrawable(context, R.drawable.thin_background_frame)); int minHeight = getMinComboHeight(context); combo1Spinner.setMinimumHeight(minHeight); combo2Spinner = new Spinner(context); LinearLayout.LayoutParams valueSpinnerParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); valueSpinnerParams.setMargins(15, 25, 15, 15); combo2Spinner.setLayoutParams(valueSpinnerParams); combo2Spinner.setPopupBackgroundDrawable(Compat.getDrawable(context, R.drawable.thin_background_frame)); combo2Spinner.setBackground(Compat.getDrawable(context, R.drawable.thin_background_frame)); combo2Spinner.setMinimumHeight(minHeight); List<String> combo2ItemsList = new ArrayList<>(); if (_combo1Value.length() > 0) { combo2ItemsList = dataMap.get(_combo1Value); int indexOf = combo1Items.indexOf(_combo1Value.trim()); if (indexOf != -1) { combo1Spinner.setSelection(indexOf, false); } } ArrayAdapter<String> combo2ListAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, combo2ItemsList); combo2ListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); combo2Spinner.setAdapter(combo2ListAdapter); combosLayout.addView(combo1Spinner); combosLayout.addView(combo2Spinner); if (_combo2Value.length() > 0) { int position = combo2ListAdapter.getPosition(_combo2Value); combo2Spinner.setSelection(position, false); } combo1Spinner.setOnItemSelectedListener(this); }