Search code examples
javaandroidspinnerandroid-spinner

Select spinner by id instead of position


How to select spinner by ID, Spinner is populated from DB, and in edit mode I want to select saved spinner ID again. Is there any build in function to solve this issue? Like we have in .net,

drp.SelectedValue

spCustomer.setId(tr.getVendCustID());

Solution

  • Here is my answer,

    for (int i = 0; i < spCustomer.getCount(); i++) {
                    if (Integer.parseInt(((PopulateSpinner) spCustomer.getItemAtPosition(i)).id) == tr.getVendCustID()) {
                        spCustomer.setSelection(i);
                        break;
                    }