android - How To Load Layout Background Using Picasso -


can point me towards example of how 1 might change xml layout's background programatically using picasso? examples i've found able update imageview using picasso - not layout background.

unable set linearlayout backgroundresource url using picasso

you can use picasso's target:

         picasso.with(this).load("http://imageurl").into(new target() {             @override             public void onbitmaploaded(bitmap bitmap, picasso.loadedfrom from) {                myourlayout.setbackground(new bitmapdrawable(bitmap));             }              @override             public void onbitmapfailed(drawable errordrawable) {              }              @override             public void onprepareload(drawable placeholderdrawable) {              }         }); 

update

as @bladecoder mentioned in comment, picasso holds weak reference target objects, hence garbage collected.

so, following jake wharton's comment on 1 of issues, think way go:

  customlayout mcustomlayout = (customlayout)findviewbyid(r.id.custom_layout)   picasso.with(this).load("http://imageurl").into(mcustomlayout); 

customlayout.java:

public class customlayout extends linearlayout implements target {      public customlayout(context context) {         super(context);     }      public customlayout(context context, attributeset attrs) {         super(context, attrs);     }      public customlayout(context context, attributeset attrs, int defstyleattr) {         super(context, attrs, defstyleattr);     }       @override     public void onbitmaploaded(bitmap bitmap, picasso.loadedfrom from) {         setbackground(new bitmapdrawable(getresources(), bitmap));     }      @override     public void onbitmapfailed(drawable errordrawable) {         //set error drawable     }      @override     public void onprepareload(drawable placeholderdrawable) {         //set placeholder     } } 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -