Reputation: 99
I just need to add setselection
method to my spinner by using the position that get from database.
I already try both(in is the position of text)
spinner.setselection(in);
spinner.setselection(in,true);
but it always shows first object in the array that used by the spinner
thanks for help
Upvotes: 0
Views: 986
Reputation: 848
Make sure your setSelection()
is called after you done with spinner's setAdapter()
.
Upvotes: 1
Reputation: 396
try this it will work
for (int i = 0; i < array.size(); i++) {
if (postion == Integer.parseInt(array.get(i))) {
spinner.setSelection(i);
break;
}
}
Upvotes: 4
Reputation: 497
Have you tried using the name of the item to get the position?
spinner.setSelection(((ArrayAdapter)spinner.getAdapter()).getPosition("Item Name"));
Upvotes: 2