Help us understand the problem. What is going on with this article?

Glide4.8 Glide - You must not call setTag() on a view Glide is targeting

More than 1 year has passed since last update.

原因 Glideがtag使ってるから

for(int i=0; i < max; i++)
{
    imageView.setTag( items.get(i) ); // ←ここで例外が上がってしまう。
    Glide.with(this)
    // (略)
        .into(imageView);
}

対策 失敗編

を参考にしてみる

public class App extends Application {
    @Override public void onCreate() {
        super.onCreate();
        ViewTarget.setTagId(R.id.glide_tag);
    }
}

src/main/values/ids.xml

<resources>
    <item type="id" name="glide_tag" />
</resources>

glide-1.png

glide-2.png

あ~この情報は古かった。

対策 成功への道

myButton.setTag(100 /* or any other integer key except 0 */, someValue);

なるほど~

これですね。

public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource {
    public void setTag(int key, final Object tag) 
    public Object getTag(int key) 

やってみよう。

    imageView.setOnClickListener(imageViewLister);
    for(int i=0; i < max; i++)
    {
        imageView.setTag(i, items.get(i) );
    }

これだと keyのi が定数じゃないよって怒られた ;(
こんなので定数切りたくない...(´・ω・`)

対策 成功編

( ✧Д✧) 自分のIDという定数あるじゃん!!

一件落着

    imageView.setOnClickListener(imageViewLister);
    for(int i=0; i < max; i++)
    {
        imageView.setTag(imageView.getId(), items.get(i) );
    }

    private View.OnClickListener imageViewLister =  new View.OnClickListener() {
        @Override
        public void onClick(View view)
        {
            Item item = view.getTag(view.getId());
        }
    };

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away