java - Output JSON image in listView -
i tried uploading image using json. create link image in json. many times tried fix problem, no success.
is there mistake in use of downloadimagetask
in adapter adapter
?
mainactivity
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); list = (listview) findviewbyid(r.id.list); newslist = new arraylist<news>(); //this take json image new newsasynktask().execute(); } public class newsasynktask extends asynctask<string , void, string> { protected string doinbackground(string... params) { //code } protected void onpostexecute(string file_url) { pdialog.dismiss(); //this run adapter newsadapter adapter = new newsadapter(getapplicationcontext(), r.layout.list_row, newslist); list.setadapter(adapter); } }
my adapter adapter
public class newsadapter extends arrayadapter<news> { 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 try load image. using wrong somthing, please me private class downloadimagetask extends asynctask<string, void, bitmap> { imageview bmimage; imageloader imgloader; public downloadimagetask(imageview bmimage) { this.bmimage = bmimage; } @override protected bitmap doinbackground(string... urls) { final string urldisplay = urls[0]; bitmap micon11 = null; try { handler handler = new handler(context.getmainlooper()); handler.post(new runnable() { @override public void run() { //this class on [link][1]. try use simple, work. here dont work imgloader = new imageloader(context); imgloader.displayimage(urldisplay, bmimage); } }); } catch (exception e) { e.printstacktrace(); } return micon11; } protected void onpostexecute(bitmap result) { bmimage.setimagebitmap(result); } } }
Comments
Post a Comment