1

I have trying to get my multi-line spinner to work, thought I can not work out why it wont! (It just shows single line - so the text runs off the edge). I have read this, but still doesn't work.

Here is my multi_line_spinner.xml file;

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="false"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight" />

And my activity (part) xml file;

    <Spinner
        android:id="@+id/schoolSpinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10" />

And here is where I programmtically set the Spinner

UPDATE: I get the data from an AsyncTask connecting to a remote server. (The data is successfully retrieved).

ArrayList<String> schoolName = new ArrayList<String>();
    getTTData task = new getTTData();
            task.execute("1");
        try {
            dataSchool = task.get();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        int x = 0;
        while(x<dataSchool.size()-1)
        {
            schoolName.add(dataSchool.get(x));
            x++;
            schoolID.add(dataSchool.get(x));
            x++;
        }


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, schoolName);
    adapter.setDropDownViewResource(R.layout.multi_line_spinner);
    schoolSpinner.setAdapter(adapter);
    schoolSpinner.setOnItemSelectedListener(this);

Where schoolName is an ArrayList of strings. Any help is much appreciated!

Community
  • 1
  • 1
Stu Whyte
  • 758
  • 5
  • 19
  • Show us how you create the array. – dymmeh Mar 12 '13 at 19:55
  • updated as requested :) – Stu Whyte Mar 12 '13 at 20:01
  • Why are you incrementing X twice in one loop? It won't cause any problems for your adapter but it just seems wrong (you'll end up missing some data). – dymmeh Mar 12 '13 at 20:07
  • Have you tried not setting adapter.setDropDownViewResource(R.layout.multi_line_spinner); to see if it works then? I'd assume that layout is the cause of the problem since everything else looks fine. – dymmeh Mar 12 '13 at 20:09
  • I increment x twice because dataSchool(0, 2, 4.....) are the names and dataSchool(1,3,5.....) are the ID's - so I just seperate them and put them into their own arrays. I have also dropped the adapter.setDropDownViewResource(R.layout.multi_line_layout), but has had no effect! – Stu Whyte Mar 12 '13 at 20:20
  • According to the link you provided, you should be setting that layout when creating the adapter.. ex. new ArrayAdapter(this, R.layout.multi_line_spinner, schoolName); – dymmeh Mar 12 '13 at 20:26
  • Yeah that still doesn't work. I have stumbled upon http://stackoverflow.com/questions/14139106/spinner-does-not-wrap-text-is-this-an-android-bug?rq=1 and I have tried it but still no luck! – Stu Whyte Mar 12 '13 at 20:52

0 Answers0