Я создаю представление рециркулятора, и моя ссылка на изображение и текстовое представление, которое извлекается с помощью findViewById, возвращает ноль.
Я пытался изменить идентификаторы и по отдельности изменить изображение и текст, но безрезультатно иЯ отлаживал весь день
Студенческий ряд
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="40dp">
<ImageView
android:id="@+id/itemImage"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"/>
<TextView
android:id="@+id/itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recycling me"
android:textSize="15sp"/>
</LinearLayout>
Адаптер
class StudentListAdapter(val list:ArrayList<Student>, internal var newInstance: onItemClickListener) : RecyclerView.Adapter<StudentListAdapter.StudentViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StudentViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.activity_student_list, parent, false)
return StudentViewHolder(view)
}
override fun getItemCount(): Int{
return list.size
}
override fun onBindViewHolder(holder:StudentViewHolder, position: Int) {
holder.title.text = list[position].name
holder.image.setImageResource(list[position].image)
// var student = list.get(position)
// holder.textView?.text = student.name
// holder.image.setImageResource(student.image)
holder.itemView.setOnClickListener {
newInstance.onItemClick(list[position])
}
}
class StudentViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
internal var title: TextView
internal var image:ImageView
init{
image = itemView.findViewById(R.id.itemImage)
title = itemView.findViewById(R.id.itemText)
}
}