I have long text that I want to put in a few, but not all, items in a spinner. Tried using the answer here but was not able to get it to work. I created and saved multiline_spinner_dropdown_item.xml in res/layout directory but still get an error "multiline_spinner_dropdown_item cannot be resolved" in Eclipse.
Asked
Active
Viewed 1.2k times
3
-
can you show the erroneous code? – MByD Sep 12 '11 at 07:38
1 Answers
8
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textColor="#ffffff"/>
Use this textview in your spinner adapter in place of the android default textview you are using in .setAdapter method of the Spinner. see below R.layout.spinner_textview textview is this textview i have posted above.
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getApplicationContext(),
R.array.Array,
R.layout.spinner_textview);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);

ud_an
- 4,939
- 4
- 27
- 43
-
Works fine, seems that the main sticking point with the original post was the use of "this" instead of "getApplicationContext()" I also had to change android:singleLine="true" to android:singleLine="false" Next issue is getting the drop down dialog to show two lines of text. I also noticed that this cannot be applied to more than one spinner contained in that activity – John Kossik Sep 12 '11 at 19:26
-
oh sry tht i forgot to change single line false. you can apply this text view to multiple spinners in same activity you have to make different adapter. – ud_an Sep 13 '11 at 04:21