Fis*_*szu 14 android android-chips
移动到 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)
我找不到导致错误的定义中真正缺少的东西。任何提示?
小智 3
我在芯片膨胀方面遇到了同样的问题,我通过切换到芯片的数据绑定布局来修复此错误,如下所示。
我还认为您应该删除 xml 中的“android:id”属性,因为您正在使用 RecyclerView 动态填充芯片。它应该会自动为你生成一个 id。
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.content.Context" />
<variable
name="element"
type="com.android.sarahmica.app.database.Element" />
</data>
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:clickable="true"
android:focusable="true"
android:text="@{element.name}"
android:tag="@{element.id}"
app:chipBackgroundColor="@{element.getChipColor(context)}"
style="@style/Widget.MaterialComponents.Chip.Filter" />
</layout>
Run Code Online (Sandbox Code Playgroud)
然后我从片段中的列表中膨胀我的芯片,如下所示(但由于您使用的是 RecylerView,因此您必须调整适配器以相应地使用数据绑定)
val chipGroup = getChipGroup(type)
val inflater = LayoutInflater.from(chipGroup.context)
elementList.forEach { element ->
val chipBinding: MyChipBinding = DataBindingUtil.inflate(inflater, R.layout.my_chip, chipGroup, true)
chipBinding.greenActivity = activity
binding.lifecycleOwner = this
}
Run Code Online (Sandbox Code Playgroud)
希望我的解决方案对你有帮助!!
| 归档时间: |
|
| 查看次数: |
12397 次 |
| 最近记录: |