创建适配器时出错

时间:2012-12-28 19:28:34

标签: android actionbarsherlock android-arrayadapter

当我想在ListView中设置包含字符串和位图的'PaysItem'列表时。 我正在使用SherlockListFragment,我在该行上有错误: ArrayAdapter<PaysItem> adapter = new ArrayAdapter<PaysItem>(getActivity().getBaseContext(), R.layout.pays_item,list);

pays_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  <ImageView
   android:id="@+id/image"
android:layout_width="50dip"
android:layout_height="50dip" android:scaleType="centerCrop"/>
 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/text_pays"
 android:textColor="#FFFFFF"
 android:background="#000000"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="14sp" >
</TextView>
</LinearLayout>

错误是:

You must supply a resource ID for a TextView

错误很明显,我必须提供TextView ID,但是如何解决?

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

错误:

  

您必须为TextView提供资源ID

表示您需要将TextView ID传递给ArrayAdapter。传递给:

ArrayAdapter<PaysItem> adapter = new ArrayAdapter<PaysItem>
        (getActivity().getBaseContext(), R.layout.pays_item,R.id.text_pays,list);

答案 1 :(得分:1)

您需要实现自己的适配器,否则您将看不到任何图片。 请看这里: How to use ArrayAdapter<myClass>