Wrapping text in spinner android [duplicate]

馋奶兔 提交于 2019-12-11 02:58:10

问题


I have long text that I want to put in a few, but not all, items in a spinner. Tried using the answer here but was not able to get it to work. I created and saved multiline_spinner_dropdown_item.xml in res/layout directory but still get an error "multiline_spinner_dropdown_item cannot be resolved" in Eclipse.


回答1:


<?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="true" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:textColor="#ffffff"/>

Use this textview in your spinner adapter in place of the android default textview you are using in .setAdapter method of the Spinner. see below R.layout.spinner_textview textview is this textview i have posted above.

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getApplicationContext(), 
                                                                         R.array.Array, 
                                                                        R.layout.spinner_textview);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);


来源:https://stackoverflow.com/questions/7384639/wrapping-text-in-spinner-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!