Spinner with long text is not working fine

I have problems with the counter. Depending on my dates, I have to add to TableRowa TextViewwith EditTextor Spinner. My array, which should appear in Spinner, is a bit long. I checked my code with an array with short texts and it looks like this:

enter image description here

The only problem here is that the spinner is not fill_parent.

If I put my array in a numeric number, it looks like this:

enter image description here

In this case, the counter is not like a counter, and EditText is no longer visible. When I select a counter, it looks like this:

enter image description here

Here I need to display the entire text of the array. This is my code:

TableRow.LayoutParams lp = new TableRow.LayoutParams(
            TableRow.LayoutParams.FILL_PARENT , TableRow.LayoutParams.WRAP_CONTENT);
tablerow_product[i] = new TableRow(viewToLoad.getContext());
tablerow_product[i].setLayoutParams(lp);

product_spinner[i] = new Spinner(viewToLoad.getContext());
product_spinner[i].setLayoutParams(lp);   product_spinner[i].setBackgroundResource(R.drawable.spinner_selector);
String[] proba={"red","blue"};  //first image is with this test array
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(viewToLoad.getContext(),  com.Orange.R.layout.my_spinner_textview,spinnerArray);                                     spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
product_spinner[i].setAdapter(spinnerArrayAdapter);
tablerow_product[i].addView(product_spinner[i]);                                            Themes_TableLayout.addView(tablerow_product[i],new TableLayout.LayoutParams(TableRow.LayoutParams.FILL_PARENT,                  TableRow.LayoutParams.WRAP_CONTENT));

and my_spinner_textview.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@drawable/textorange_selected"
    android:gravity="left"
    android:singleLine="false"
    android:ellipsize="end"/>

Can someone help me solve this problem? Any idea is welcome. Thanks in advance.

+5
3

:

Spinner language = (Spinner) findViewById(com.Orange.R.id.current_language_text);

ArrayAdapter adapter = new ArrayAdapter(this,
                com.Orange.R.layout.my_spinner_textview, languages);
adapter.setDropDownViewResource(com.Orange.R.layout.multiline_spinner_dropdown_item);
language.setAdapter(adapter);

String[] my_spinner_textview.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textview_spinner"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@drawable/textorange_selected" 
    android:paddingLeft="5dp"
    android:singleLine="true"
    android:ellipsize="end"
 />
+2

, .

class SpinnerAdapter extends ArrayAdapter<String> 
{
    Context context;
    List<String> items;
    public SpinnerAdapter(final Context context,
            final int textViewResourceId, List<String> vendor_name) {
        super(context, textViewResourceId, vendor_name);
        this.items = vendor_name;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(android.R.layout.simple_spinner_item, parent, false);
        }
        // android.R.id.text1 is default text view in resource of the android.
        // android.R.layout.simple_spinner_item is default layout in resources of android.

        TextView tv = (TextView) convertView.findViewById(android.R.id.text1);
        tv.setText(items.get(position));
        tv.setTextColor(Color.BLACK);
        tv.setTextSize(9);
          return convertView;
    }
    }

SpinnerAdapter

+1

I just did with a custom text view, for example:

ArrayAdapter myAdapter = new ArrayAdapter(context, R.layout.text_view, reasonTypesList);
myAdapter.setDropDownViewResource(R.layout.text_view);
mySpinner.setAdapter(myAdapter);

and here is the layout text_view:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/spinnerTextView"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="@dimen/padding"
    android:text="Custom Text with multi lines" />
0
source

All Articles