如何解决使用BottomSheetLayout进行数据绑定?
我正在使用带有以下 UI 和数据绑定的底部工作表
<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"
app:behavior_hideable="false"
app:behavior_peekHeight="16dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<data>
<variable
name="question"
type="String" />
<variable
name="options1"
type="String" />
<variable
name="options2"
type="String" />
<variable
name="options3"
type="String" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/parentSheetLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_chat_feedback"
android:paddingStart="10dp"
android:paddingTop="10dp"
android:paddingEnd="10dp"
android:paddingBottom="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/headerImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_chat_feedback_header" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/feedbackQuestion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@{question}"
android:textColor="@android:color/white"
android:textSize="20sp"
app:fontFamily="@font/font_semi_bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/headerImg"
tools:text="@string/feedback_feeling_better" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/feedbackOptionsContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/feedbackQuestion">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/option1"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="@drawable/bg_feedback_questionairre"
android:gravity="center"
android:text="@{options1}"
tools:text="@string/yes"
android:textColor="@android:color/white"
android:textSize="14sp"
app:fontFamily="@font/font_regular"
app:layout_constraintEnd_toStartOf="@+id/option2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/option2"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:background="@drawable/bg_feedback_questionairre"
android:gravity="center"
android:text="@{options2}"
tools:text="@string/maybe"
android:textColor="@android:color/white"
android:textSize="14sp"
app:fontFamily="@font/font_regular"
app:layout_constraintEnd_toStartOf="@+id/option3"
app:layout_constraintStart_toEndOf="@+id/option1"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/option3"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="@drawable/bg_feedback_questionairre"
android:gravity="center"
android:text="@{options3}"
tools:text="@string/nopes"
android:textColor="@android:color/white"
android:textSize="14sp"
app:fontFamily="@font/font_regular"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/option2"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
我正在更新片段类中的绑定变量
private fun updateFeedbackData(question: FeedbackQuestion): View {
val binding = FeedbackBinding.inflate(
layoutInflater,null,false
)
binding.question = question.question
question.options?.let {
binding.options1 = it[0]
binding.options2 = it[1]
binding.options3 = it[2]
}
return binding.root
}
但是数据没有在视图上更新 我无法弄清楚可能是什么问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。