ArrayAdapter requires the resource ID to be a TextView

      

在测试Spinner的时候,使用ArrayAdapter作为构造器,运行的时候报错,如上图:

代码:

List<String> list = new ArrayList<String>();
        list.add("张三");
        list.add("lisi");
        list.add("wangwu");
        list.add("张三");
        ArrayAdapter adapter = new ArrayAdapter(this,R.layout.item,list);
        
        spLB.setAdapter(adapter);

 

构造的Item显示布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView
        android:id="@+id/textItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=".."
        ></TextView>
</LinearLayout>

百度得知,ITEM布局文件的根节点应该是TextView,修改即可

posted @ 2015-07-14 17:20  大侠的哥哥是菜鸟  阅读(896)  评论(0编辑  收藏  举报