Android 创建适配器时出错
当我想在ListView中设置包含字符串和位图的“PaysItem”列表时。 我使用的是一个Android 创建适配器时出错,android,actionbarsherlock,android-arrayadapter,Android,Actionbarsherlock,Android Arrayadapter,当我想在ListView中设置包含字符串和位图的“PaysItem”列表时。 我使用的是一个SherlockListFragment,我在那一行有一个错误: ArrayAdapter=newArrayAdapter(getActivity().getBaseContext(),R.layout.pays\u项目,列表) pays_item.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr
SherlockListFragment
,我在那一行有一个错误:
ArrayAdapter=newArrayAdapter(getActivity().getBaseContext(),R.layout.pays\u项目,列表)代码>
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>
错误很明显,我必须提供TextView ID,但如何解决
谢谢您的帮助。错误:
必须为TextView提供资源ID
意味着您需要将TextView id传递给ArrayAdapter
。将其作为:
ArrayAdapter<PaysItem> adapter = new ArrayAdapter<PaysItem>
(getActivity().getBaseContext(), R.layout.pays_item,R.id.text_pays,list);
ArrayAdapter适配器=新的ArrayAdapter
(getActivity().getBaseContext(),R.layout.pays\u item,R.id.text\u pays,list);
您需要实现自己的适配器,否则将看不到任何图片。
请看这里:
是,没有FC编号。但是,我的结果有误。但是你回答了我的问题。将在6分钟内完成acecpt。谢谢你,伙计。@Andronienn:我的答案是根据你的问题,但如果你想在ListView中显示图像和文本,那么就使用SimpleAdapter并创建自定义适配器。看一个例子,我认为对你的情况更有帮助。我试着提出了一个新问题。如果图像是从URL链接中获取的呢?hashmap/列表是否可以存储Drawable,然后在SimpleAdapter中设置它们?
ArrayAdapter<PaysItem> adapter = new ArrayAdapter<PaysItem>
(getActivity().getBaseContext(), R.layout.pays_item,R.id.text_pays,list);