我是Kotlin和Android开发的新手,我想制作一个包含ImageView列表视图的片段,但出于某种奇怪的原因,我得到一个错误,上面说:
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
这是我的片段.kt码
var array = arrayOf(
R.drawable.serbia,
R.drawable.croatia,
R.drawable.bulgaria,
R.drawable.azerbejdzan,
R.drawable.hungari)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val context = context as MainActivity
val lv = context.findViewById(R.id.listview_1) as ListView
val adapter = ArrayAdapter(context, R.layout.simple_list_item_1, R.id.image1, array)
lv.adapter = adapter
}
这是我的简单 list .xml
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
tools:ignore="ContentDescription">
</ImageView>
我使用了一个字符串列表和一个文本视图,效果很好,但我似乎不知道如何处理图像.有什么建议吗?