android - how do I transform a string of url's into drawable? -
i have arraylist follows:
private void loadimages() { images = new arraylist<>(); images.add(getresources().getdrawable(r.drawable.imag1)); images.add(getresources().getdrawable(r.drawable.imag2)); images.add(getresources().getdrawable(r.drawable.imag3)); }
i want able convert url these drawables such that:
drawable1 = "http.someimage.com/image.png" drawable2 = "http.someimage.com/newimage.png"
followed
private void loadimages() { images = new arraylist<>(); images.add(getresources().getdrawable(drawable1)); images.add(getresources().getdrawable(drawable2)); ...etc }
is there easy way go around this? want stick drawables ,but cant find way convert url drawable ideas? thanks!
if have url of picture need download first.
you can't "convert" url drawable.
you need this:
url url = new url("http.someimage.com/image.png"); bitmap bmp = bitmapfactory.decodestream(url.openconnection().getinputstream());
then if need add image imageview object can call method .setimagebitmap(bmp). otherwise there ways extract drawable object bitmap can check previous answer. once have drawable can add arraylist.
hope got question right
p.s.: sure not on main thread since network operation! use thread or asynctask
Comments
Post a Comment