0

When I make the spinner with very long text, the spinner button (not drop down menu), which usually shows the selected text and the triangle image(▼), doesn't show the triangle image. I tested with normal (android.R.layout.simple_spinner_item) layout and multiline layout. But neither did.

The right side of spinner button is the outside of the window. (Sorry, I can't attach the image because I'm a new user.)

The sources are following;

SpinnerTestActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class SpinnerTestActivity extends Activity {
String[] mStrings = {"verrrrrrrrrry looooooooooooooong",
        "abc loooooooooooooooooooooooooong",
        "xyz"
};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Spinner spinner = (Spinner)findViewById(R.id.spinner1);
//       ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, mStrings);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.multiline_spinner_item, mStrings);
            spinner.setAdapter(adapter);
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </TableRow>
</TableLayout>

multiline_spinner_item.xml

<?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="false"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />
Nishimu
  • 109
  • 2
  • 7

2 Answers2

1

Thank you for your observations on my question.

I found the answer.

add

spinner.getLayoutParams().width = spinner.getWidth();

after

spinner.setAdapter(adapter);
Nishimu
  • 109
  • 2
  • 7
0

Have you defined the android:prompt attribute in your Android Spinner controller?

It will help you. Please see the following code:

<Spinner 
    android:id="@+id/spinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/planet_prompt"
/>

You can refer to the following link: Can an Android AsyncTask doInBackground be synchronized to serialize the task execution?

Community
  • 1
  • 1
code post
  • 81
  • 5
  • My poor english caused misunderstanding. So I modified my question. My question is about a spinner button, not a drop menu of spinner. – Nishimu Mar 29 '12 at 11:16