移动到 android-x 后,我注意到有很多日志说:
"E/itterforandroi: Invalid ID 0x00000000."
Run Code Online (Sandbox Code Playgroud)
我设法循环到创建新 RecyclerView ViewHolder 并膨胀包含 Chip 的布局的地步。其他所有字段都不会显示这样的错误,只有 Chip。
在 xml 中它看起来像这样:
<com.google.android.material.chip.Chip
android:id="@+id/someChip"
style="@style/Widget.MaterialComponents.Chip.Action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
app:chipIcon="@drawable/ic_account_circle_black_24dp"
app:chipIconEnabled="true" />
Run Code Online (Sandbox Code Playgroud)
我找不到导致错误的定义中真正缺少的东西。任何提示?
我有一个问题与 MVVM 的正确设计和架构有关,而不是与编码本身有关。在我的项目中,我遇到了一种情况,即 ViewModel 正在提供数据,稍后在 RecyclerView.Adapter 中使用这些数据来创建正确的视图。
但是,我想知道如果某些数据将以 ID 的形式提供以进一步从 Room 或外部服务器获取,这是否也是正确的(从正确的“做事方式”POV)?例如在 onBindViewHolder 期间使用一些 LiveData 和 observe() 以在成功加载时更新某些字段。