【Bug】The key must be an application-specific resource id.

    UncaughtException detected: java.lang.IllegalArgumentException: The key must be an application-specific resource id.
        at android.view.View.setTag(View.java:24464)

View的setTag方法可以为这个View绑定一个对象,这里我使用的是setTag(int key, Object value)方法
这个方法的key传入一个唯一的int类型值都不行,得在资源文件中定义一个id类型得字段,如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="gift_act_banner_view_tag" type="id"/>
</resources>

设置:

giftActBannerIv.setTag(R.id.gift_act_banner_view_tag,selectedGift);

取出:

GiftModel gift = (GiftModel) giftActBannerIv.getTag(R.id.gift_act_banner_view_tag);

需要注意的是imageview 不要直接settag可能会加载不出来图片。可以使用 settag(id, value) 的方法

发布了110 篇原创文章 · 获赞 19 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40833790/article/details/103904103