androidBeckhamania androidBeckhamania - 3 months ago 15x
Android Question

How to keep a value selected in android spinner based on database value?

I have populated an android spinner from database in one activity.
But on the edit part of activity I wanna keep the android spinner selected to particular value equivalent to current record.
When I use


It keeps it selected by position I wanna keep it selected by ID or value based from record in db.
Thanks In Advance.


you can use this method after poputlating spinner. pass spinner and value to this method.

public static void setSpinnerValue(Spinner spin, String value) {

    for (int i = 0; i < spin.getCount(); i++) {
        if (spin.getItemAtPosition(i).toString().equalsIgnoreCase(value)) {