在迁移到android-x之后,我注意到有很多日志说:
"E/itterforandroi: Invalid ID 0x00000000."我设法向下循环,直到我创建了一个新的RecyclerView芯片并膨胀了一个包含芯片的布局。其他所有字段都不会显示这样的错误,只有芯片会显示。
在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" />我找不到这个定义中真正缺少的导致错误的东西。有什么提示吗?
发布于 2020-08-22 09:14:16
我遇到了同样的芯片膨胀问题,我通过切换到数据绑定布局修复了这个错误,如下所示。
我还认为您应该删除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>然后我从片段中的a列表中膨胀芯片,如下所示(但由于您使用的是RecycylerView,因此必须调整适配器以使用相应的数据绑定)
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
}我希望我的解决方案能帮助你!
https://stackoverflow.com/questions/55504545
复制相似问题