【问题标题】:Spinner with long text not working fine带有长文本的微调器无法正常工作
【发布时间】:2012-07-30 11:32:12
【问题描述】:

我的微调器有一些问题。根据我的日期,我必须添加到 TableRowTextViewEditTextSpinner。我必须在 Spinner 中显示的数组有点长。我用一个带有短文本的数组测试了我的代码,它看起来像这样:

这里唯一的问题是微调器不是fill_parent

如果我将数组放入微调器,它看起来像这样:

在这种情况下,微调器看起来不像微调器,并且 EditText 不再可见。当我选择微调器时,它会出现这个视图:

这里我需要显示数组的所有文本。 这是我的代码:

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));

和 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"/>

谁能帮我解决?欢迎任何想法。提前致谢。

【问题讨论】:

标签: android spinner tablerow


【解决方案1】:

对于我的问题,我找到了这个解决方案:

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"
 />

【讨论】:

  • 对我不起作用。我的 textview 的 XML 是: schemas.android.com/apk/res/android" android:id="@android:id/text2" style="?android:attr/spinnerItemStyle" android:background="@color/edit_text_grey_bckground_color" android :singleLine="true" android:layout_width="match_parent" android:layout_height="?attr/dropdownListPreferredItemHeight" android:padding="11dp" android:drawableRight="@drawable/ic_nav_down" android:textSize="15dp" android:textColor ="@color/blue" android:ellipsize="end" />
【解决方案2】:

我只是使用了自定义文本视图,例如:

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

这是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" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 2018-11-04
    • 2016-08-04
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多