首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android芯片膨胀导致“无效ID 0x00000000”。

Android芯片膨胀导致“无效ID 0x00000000”。
EN

Stack Overflow用户
提问于 2019-04-04 05:26:36
回答 1查看 14.7K关注 0票数 16

在迁移到android-x之后,我注意到有很多日志说:

代码语言:javascript
复制
"E/itterforandroi: Invalid ID 0x00000000."

我设法向下循环,直到我创建了一个新的RecyclerView芯片并膨胀了一个包含芯片的布局。其他所有字段都不会显示这样的错误,只有芯片会显示。

在xml中,它看起来像这样:

代码语言:javascript
复制
<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" />

我找不到这个定义中真正缺少的导致错误的东西。有什么提示吗?

EN

回答 1

Stack Overflow用户

发布于 2020-08-22 09:14:16

我遇到了同样的芯片膨胀问题,我通过切换到数据绑定布局修复了这个错误,如下所示。

我还认为您应该删除xml中的"android:id“属性,因为您正在使用RecyclerView动态填充芯片。它应该会自动为你生成一个id。

代码语言:javascript
复制
<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,因此必须调整适配器以使用相应的数据绑定)

代码语言:javascript
复制
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
}

我希望我的解决方案能帮助你!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55504545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档