I'm doing an Android app which can get data from a web service & load it into spinner. I need to maintain the selected data state of the spinner while I go to some screen & come back. For example, if I'm getting data from the web service as 1.apple 2.orange 3.grapes & loading it into the spinner, then I select orange. When I go to some other screen & come back, the selected spinner data should be orange. But it again loads data from the server into the spinner. Can anybody help me to resolve this?
My code:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... if (Constants.SPINNER != null ) { spinner.setSelection( Constants.SPINNER); } else { //WebCall here for getting data } //... spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int arg2, long arg3) { Constants.SPINNER = spinner.getSelectedItemPosition(); In Constant class:
public static Integer SPINNER="";