Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spinner not showing selected item in android

Tags:

android

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..

like image 733
Krishna Avatar asked Mar 14 '13 09:03

Krishna


1 Answers

When adding item dynamically to the adapter, if not calling the:

adapter.notifyDataSetChanged();

selecting an added item would not be shown in the UI.

like image 173
TacB0sS Avatar answered Oct 14 '22 03:10

TacB0sS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!