Error “You must not call setTag() on a view Glide is targeting” when use Glide

前端 未结 8 685
悲哀的现实
悲哀的现实 2020-12-13 09:15

I use Glide library inner custom adapter view in my apps. But I have Error :

\"You must not call setTag() on a view Glide is targeting\" 

T

8条回答
  •  别那么骄傲
    2020-12-13 09:39

    If you have freedom to use other library, use, else you can use setTag(int, Object), but if you can't do above then wrap ImageView in a basic LinearLayout > setTag() on LinearLayout > setOnClickListener on LinearLayout.

    Something like :

    LinearLayout imgViewLinearLayout = new LinearLayout(context);
                imgViewLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
                imgViewLinearLayout.setId(R.id.dummy_image_layout);
                imgViewLinearLayout.setOnClickListener(this);
    
    ImageView imageView = new ImageView(inflater.getContext());
                    imageView.setPadding(0,15,20,0);
    
                    imageView.setId(R.id.imageview_for_glide);
    
                    imgViewLinearLayout.setTag("Image VIEWTAG");
    imgViewLinearLayout.addView(imageView)
    

    Override onClick and :

    @Override
        public void onClick(View v) {
    
            if(v.getId() == R.id.dummy_image_layout){
                //Do what you wanna wanted to do on click of ImageView
            }
        }
    

    Hope this helps.

提交回复
热议问题