Reputation: 59
I have populated spinner values with json data and posted it into a Web Service. Now i have the option to edit all the info. When i click on edit the value that was stored previously in the spinner must to pre-populated as the first item along with other json vales.
nationality_name1.add(jsonObject1.getString("NATIONALITY"));
SprStudentEnrolmentNationality.setAdapter(new ArrayAdapter<String>(ManagementEnhancementProgramStudentEnrolment.this,
android.R.layout.simple_list_item_1, nationality_name1));
SprStudentEnrolmentNationality.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
populateNationality();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
By doing like this the spinner would first be populated by the value that was stored on then displays all items and the first item is no longer in the first position.
Upvotes: 0
Views: 40
Reputation: 4141
For that you have to manually play with the list populating the spinner and bring to first position.
I would rather suggest you to use the below code which would directly point to your selected element.
spinnerObject.setSelection(INDEX_OF_PREVIOUS_VALUE)
Upvotes: 1