URAndroid
URAndroid

Reputation: 6277

Load Image From URL into ListView

How to load image in imageView for List item from an URL.

Upvotes: 0

Views: 1402

Answers (4)

Anushree Rastogi
Anushree Rastogi

Reputation: 11

Try this code:

string path = item.ImgPath;
URL url = new URL(path);
URI uri = new URI(url.Protocol, url.UserInfo, url.Host, url.Port, url.Path, url.Query, url.Ref);
url = uri.ToURL();

//convert it into bitmap
var bitmap = Android.Graphics.BitmapFactory.DecodeStream(url.OpenStream());

//set bitmap drawable
System.IO.Stream stream = url.OpenStream();
Img.SetImageBitmap(bitmap); 

Upvotes: 0

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

Try Below code :

try
{
     URL img_value = null;
     img_value = new URL("ImageUrl");
     Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
     Image.setImageBitmap(mIcon1);
}
catch(Exception e)
{
}

Upvotes: -1

Hun
Hun

Reputation: 3798

I used this in getView() in ListView adapter.

Webview kWebview = new Webview(context);
kWebview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
kWebview.setFocusable(false);
kWebview.setClickable(false);
kWebview.setLongClickable(false);
kWebview.setFocusableInTouchMode(false);
kWebview.setInitialScale(100);
kWebview.setBackgroundColor(Color.BLACK);

WebSettings kSet = kWebview.getSettings();
kSet.setLoadWithOverviewMode(false);
kSet.setLoadsImagesAutomatically(true);
kSet.setAppCacheEnabled(true);
kSet.setAppCachePath(_context.getCacheDir().toString());
kSet.setCacheMode(WebSettings.LOAD_DEFAULT);
kSet.setAllowFileAccess(true);
kSet.setDomStorageEnabled(true);

kWebview.loadUrl("http://image_url");

Webview is more smoothly load than ImageView

Upvotes: 0

a fair player
a fair player

Reputation: 11786

Simply you can use this library

which uses the concept of lazy loading.

Upvotes: 3

Related Questions