Monday, 15 September 2014

android - setting array of urls to imageview in imageadapter -



android - setting array of urls to imageview in imageadapter -

i getting problem @ connection.connect();

android.os.networkonmainthreadexception in android

i getting error how set asychtask imageadapter unable display url image in imageview

public class imageadapter extends baseadapter { private context context; public static final string[] videos={ "http://img.youtube.com/vi/qshntqsil7y/1.jpg","http://img.youtube.com/vi/5_-tl63516w/1.jpg", "http://img.youtube.com/vi/cdeg9npvba0/1.jpg"}; private imageview imageview; public imageadapter(context c) { // todo auto-generated constructor stub context=c; } @override public int getcount() { // todo auto-generated method stub homecoming videos.length; } @override public object getitem(int position) { // todo auto-generated method stub homecoming videos[position]; } @override public long getitemid(int position) { // todo auto-generated method stub homecoming 0; } @override public view getview(int position, view convertview, viewgroup parent) { // todo auto-generated method stub imageview imageview = new imageview(context); imageview.setimagebitmap(getbitmapfromurl(videos[position])); homecoming imageview; } public static bitmap getbitmapfromurl(string src) { seek { url url = new url(src); httpurlconnection connection = (httpurlconnection) url .openconnection(); connection.setdoinput(true); connection.connect(); inputstream input = connection.getinputstream(); bitmap mybitmap = bitmapfactory.decodestream(input); homecoming mybitmap; } grab (exception ex) { ex.printstacktrace(); homecoming null; } }

this exception thrown when application attempts perform networking operation on main thread in honeycomb or later...so in order perform async loading of images in list view can utilize lazy loading concept.... there alot of libraries it...please find link of some....

https://github.com/nostra13/android-universal-image-loader

how do lazy load of images in listview

hope helps

android video

No comments:

Post a Comment