Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

populating a spinner items with multiple lines

Some items in my spinner are long and I would like the spinner to wrap the text over multiple lines depending on how long the text is. I looked over serval solutions for this but they are not working for me.

Here showing the text not fitting:

enter image description here

Here is my code in Java:

public void addItemsOnSpinner3() {

        spinner3D = (Spinner) findViewById(R.id.activities1);
        List<String> list = new ArrayList<String>();
        list.add("Academic Year Opening Program");
        list.add("Academic Year Closing Program");
        list.add("LR1: Defining Primary Care, Health Care Disparities & Vulnerable Populations");
        list.add("LR2: Community Resources and the Elderly");
        list.add("LR3: Inter-professional Teams and the Homeless");
        list.add("LR4: Quality Improvement and Veterans");
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                R.layout.multiline_spinner_row, list);
        dataAdapter.setDropDownViewResource(R.layout.multiline_spinner_row);
        spinner3D.setAdapter(dataAdapter);
    }

I created a custom row called "multiline_spinner_row.xml" where singleline is changed to false:

<TextView android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="false"
    xmlns:android="http://schemas.android.com/apk/res/android" />

All this does is make my selection wrap the text but not the items:

enter image description here

Any help would be greatly appreciated! Thanks in advance!

like image 606
Mido2009 Avatar asked Jan 28 '23 10:01

Mido2009


1 Answers

in spinner set this property:

android:spinnerMode="dialog"

in text view set these properties:

android:layout_weight="1"  
android:ellipsize="none"  
android:maxLines="100"  
android:scrollHorizontally="false"
like image 92
ygngy Avatar answered Jan 31 '23 20:01

ygngy