我正在尝试使用baseAdapter创建一个列表视图,该列表视图为每个项目(每个项目的图像和文本)显示带有文本视图的ImageView。但是,列表视图滚动太慢且太慢。
class MyListAdapter:BaseAdapter {
var ListLocal = ArrayList<Food>()
var mCtx : Context?=null
constructor(List:ArrayList<Food>,mCtx:Context){
this.ListLocal = List
this.mCtx = mCtx
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?):
View {
var convertView = convertView
var holder: ViewHolder
if (convertView == null) {
holder= ViewHolder()
var inflator = LayoutInflater.from(mCtx)
convertView = inflator.inflate(R.layout.food_type,null)
holder.title= convertView.findViewById(R.id.txtT)
holder.img = convertView.findViewById(R.id.PicT)
convertView.tag = holder
}
else {
holder = convertView.tag as ViewHolder
}
val item = ListLocal[position]
holder.title!!.text = item.txtname
holder.img!!.setImageResource(item.picc!!)
return convertView!!
}
override fun getItem(position: Int): Any {
return ListLocal[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getCount(): Int {
return ListLocal.size
}
}
internal class ViewHolder {
var title: TextView? = null
var img: ImageView? = null
}