java - Adapters not output image(android) -
sorry english. using adapter, , may wrong somthing using it. trying show image , textview output. textview coming in output, image not. please me, try many many times fix it. load image in downloadimagetask
. in downloadimagetask
have class imageloader
, have used this tutorial. don't have error, have nothing(
arraylist<news> arraylistnews; int resourse; context context; layoutinflater vi; public newsadapter(context context, int resource, arraylist<news> objects) { super(context, resource, objects); arraylistnews = objects; resourse = resource; this.context = context; vi = (layoutinflater) context.getsystemservice(context.layout_inflater_service); } @override public view getview(int position, view convertview, viewgroup parent) { viewholder holder; if(convertview == null) { convertview = vi.inflate(resourse, null); holder = new viewholder(); holder.imageview = (imageview) convertview.findviewbyid(r.id.imagenews); holder.namenews = (textview) convertview.findviewbyid(r.id.namenews); holder.daynews = (textview) convertview.findviewbyid(r.id.daynews); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } new downloadimagetask(holder.imageview).execute(arraylistnews.get(position).getimagenews()); holder.namenews.settext(arraylistnews.get(position).getnamenews()); holder.daynews.settext(arraylistnews.get(position).getdaynews()); return convertview; } static class viewholder { public imageview imageview; public textview namenews; public textview daynews; } //this class set image private class downloadimagetask extends asynctask<string, void, string> { imageview bmimage; imageloader imgloader; public downloadimagetask(imageview bmimage) { this.bmimage = bmimage; } @override protected string doinbackground(string... urls) { string urldisplay = urls[0]; return urldisplay; } protected void onpostexecute(string result) { imgloader = new imageloader(context.getapplicationcontext()); imgloader.displayimage(result, bmimage); } }
i suggest use picasso library. easy use. add dependency(android studio) or add .jar file library(in eclipse).
picasso.with(context).load("http://i.imgur.com/dvpvklr.png").into(imageview);
that's it. not need asynctask
download images.
your getview()
be
@override public view getview(int position, view convertview, viewgroup parent) { viewholder holder; if(convertview == null) { convertview = vi.inflate(resourse, null); holder = new viewholder(); holder.imageview = (imageview) convertview.findviewbyid(r.id.imagenews); holder.namenews = (textview) convertview.findviewbyid(r.id.namenews); holder.daynews = (textview) convertview.findviewbyid(r.id.daynews); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } // not sure return value of arraylistnews.get(position).getimagenews(); // should url pointing image file picasso.with(context).load(arraylistnews.get(position).getimagenews()).into(holder.imageview); holder.namenews.settext(arraylistnews.get(position).getnamenews()); holder.daynews.settext(arraylistnews.get(position).getdaynews()); return convertview; }