好的,我来翻译一下:
ToDoData(待办事项数据)
我的适配器(Recyclerview 适配器)
好的,所以我正在尝试在我的RecyclerView适配器中实现数据绑定,但是我需要帮助,因为我不知道该怎么做?这就是为什么我想要从我的RecyclerView适配器中删除样板代码。请查看下面的代码:
custom_row(Recyclerview项目布局)
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="toDoData"
type="com.jovanovic.stefan.tododemo.data.ToDoData" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/row_background"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@drawable/item_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/title_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:text="@{toDoData.title}"
android:textColor="@color/darkGray"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/description_txt"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:maxLength="160"
android:maxLines="3"
android:text="@{toDoData.description}"
android:textColor="@color/darkGray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/title_txt"
app:layout_constraintTop_toBottomOf="@+id/title_txt" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
ToDoData(待办事项数据)
@Parcelize
@Entity(tableName = "todo_table")
data class ToDoData(
@PrimaryKey(autoGenerate = true)
var id: Int,
var title: String,
var priority: Int,
var description: String
) : Parcelable
我的适配器(Recyclerview 适配器)
class MyAdapter: RecyclerView.Adapter<MyAdapter.MyViewHolder>() {
class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.custom_row, parent, false)
return MyViewHolder(view)
}
override fun getItemCount(): Int {
TODO("Not yet implemented")
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
TODO("Not yet implemented")
}
}