I'm using Spinner in my Application, while resuming from another screen, it is displaying the first item in it, but the old item is selected. I'm using the following code, Any one please help me.
Spinner= (Spinner) findViewById(R.id.spinner1);
dataAdapter=null;
dataAdapter = new ArrayAdapter<String>(this,android.
R.layout.simple_spinner_item, country);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner.setAdapter(dataAdapter);
if (myPrefs.getBoolean("isChecked", false)) {
Spinner.setSelection(myPrefs.getInt("PreviouslyselectedID", 0));
}
else
{
country.add(0, "Please Select");
}
Thanks in advance..
When adding item dynamically to the adapter, if not calling the:
adapter.notifyDataSetChanged();
selecting an added item would not be shown in the UI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With