Setting selected item of Spinner by value rather than by position

0 votes

I want to preselect the value that is stored in the database for a Spinner but I can't find the indexOf method of the Adapter. Can someone help me out of this?

void setSpinner(String value)
    int position = getSpinnerField().getAdapter().indexOf(value);
Aug 10, 2018 in Java by misc.edu04
• 1,380 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Suppose your Spinner is named newSpinner, and it contains as one of its choices: "xyz".

To find and compare the position of "xyz" in the Spinner, you can use the following:

String compareValue = "xyz";
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.select_state, android.R.layout.simple_spinner_item);
if (compareValue != null) {
    int spinnerPosition = adapter.getPosition(compareValue);
answered Aug 10, 2018 by 93.lynn
• 1,550 points

Related Questions In Java

0 votes
1 answer

Rotate elements of array by n position

Here is what I came up with,  import ...READ MORE

answered Mar 3 in Java by Priyaj
• 56,140 points
0 votes
1 answer

Sort a Map<Key, Value> by values

This might help solve your problem...!!!! public class ...READ MORE

answered Apr 18, 2018 in Java by Rishabh
• 3,520 points
0 votes
2 answers

How to sort an ArrayList of custom object by property in Java?

You can Sort using java 8 yourList.sort(Comparator.comparing(Classname::getName)); or -> ...READ MORE

answered Aug 13, 2018 in Java by samarth295
• 2,190 points
0 votes
1 answer

Is Java “pass-by-reference” or “pass-by-value”?

Think of reference parameters as being aliases ...READ MORE

answered Jun 8, 2018 in Java by Rishabh
• 3,520 points
0 votes
1 answer

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

In your Eclipse IDE, go into Window > Preferences > Java > Installed JREs > ...READ MORE

answered Jun 18, 2018 in Java by parth295
• 4,600 points
0 votes
1 answer

A Java collection of value pairs? (tuples?)

The Pair class is one of those ...READ MORE

answered Jul 2, 2018 in Java by sharth
• 3,310 points
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,360 points

edited Nov 6, 2018 by Omkar 5,204 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.