class TimeListAdapter: RecyclerView.Adapter<TimeListAdapter.TimeListViewHolder>() {
private var datalist1:ArrayList<TimeListShowModel> = ArrayList()
fun addItems(items:ArrayList<TimeListShowModel>){
this.datalist1=items
Log.e("test",datalist1.size.toString())
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup,viewType: Int): TimeListViewHolder {
val view=LayoutInflater.from(parent.context).inflate(R.layout.time_list,null,false)
return TimeListViewHolder(view)
}
override fun onBindViewHolder(holder: TimeListAdapter.TimeListViewHolder, position: Int) {
var t=datalist1[position]
Log.e("test1",datalist1.size.toString())
holder.bindView(t)
}
override fun getItemCount(): Int =datalist1.size?:0
class TimeListViewHolder(var view: View):RecyclerView.ViewHolder(view) {
private var tv1=view.findViewById<TextView>(R.id.tv1)
private var tv2=view.findViewById<TextView>(R.id.tv2)
private var tv3=view.findViewById<TextView>(R.id.tv3)
private var tv4=view.findViewById<TextView>(R.id.tv4)
private var tv5=view.findViewById<TextView>(R.id.tv5)
private var tv6=view.findViewById<TextView>(R.id.tv6)
fun bindView(t:TimeListShowModel){
tv1.text=t.shichang.toString()
Log.e("shichang",t.shichang.toString())
if (t.haishang!=0)tv2.text=t.haishang.toString()
if (t.yehang!=0)tv3.text=t.yehang.toString()
tv4.text=t.shiduan
tv5.text=t.kemu
tv6.text=t.jixing
}
}
}传入数据了,在addItems打印有个数,但在getItemCount一直为0,recycleview一直不显示,各位大佬帮忙看下:打印信息是E/test: 2