Shellz
Shellz

Reputation: 99

spinner set selection doesn't working

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

Answers (3)

Godfather
Godfather

Reputation: 848

Make sure your setSelection() is called after you done with spinner's setAdapter().

Upvotes: 1

megha jagdale
megha jagdale

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

enifeder
enifeder

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

Related Questions