Create a pojo class
public class SpinnerUtils {
public SpinnerUtils(String spinnerText, int value) {
this.spinnerText = spinnerText;
this.value = value;
}
public String getSpinnerText() {
return spinnerText;
}
public int getValue() {
return value;
}
public String toString() {
return spinnerText;
}
String spinnerText;
int value;
}
Then
SpinnerUtils items[]=new SpinnerUtils[array.length()];
items[i] = new SpinnerUtils(c.getString("name"), c.getInt("id"));
for (int i = 0; i <array.length(); i++) {
items[i] = new SpinnerUtils(c.getString("name"), c.getInt("id"));
}
ArrayAdapter<SpinnerUtils> adapter = new ArrayAdapter<SpinnerUtils>(this,android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
where s is your spinner. To retrieve the id:
SpinnerUtils d = items[position];
int standard = d.getValue();
Create the above 2 lines within the setOnItemSelectedListener
of the spinner to get the id.I have given you a rough idea.Hope it will work.