Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping text in spinner android [duplicate]

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.

like image 818
John Kossik Avatar asked Mar 23 '26 21:03

John Kossik


1 Answers

<?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);
like image 65
ud_an Avatar answered Mar 25 '26 09:03

ud_an



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!