The first year from the data array is shown instead of the text from prompt in my spinner. I tried adding the prompt in XML, but I also tried from code. Furthermore, it gives me a "resource not found error", when adding the spinnerSelector attribute.
<Spinner
android:id="@+id/spinnerYear"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:drawSelectorOnTop="true"
android:padding="5dip"
android:prompt="@string/spinner_header"
android:background="@drawable/selector_yearspinnerback"
android:layout_below="@+id/linearLayout_gender_btns"
android:layout_centerHorizontal="true"></Spinner>
-- android:spinnerSelector="@drawable/category_arrow"
ArrayList<String> yearList = new ArrayList<String>();
int now = new Date().getYear() + 1900;
for (int i = now; i > now - 110; i--) {
yearList.add(i + "");
}
Spinner spinner = (Spinner) findViewById(R.id.spinnerYear);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, yearList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Perhaps you are seeing the spinner drop down items as list without any prompt text. There are two modes in which spinner shows the items, dropdown and dialog.
Add this attribute to your spinner as an XML atrtribute:
android:spinnerMode="dialog"
And you will now get items in a popup dialog select list instead of drop down list.
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