Android custom CursorAdapter with AsyncTask -
i'm trying build list image taken device , text. turns out taking images phone phone's camera task takes while i'm trying make fast possible user experience won't slower. got looks images loaded in 1 imageview
, images spread other imageviews
(i'm not sure implementation of viewholder
technique , custom cursoradapter
correct).
public class mycustomcurseradapter extends cursoradapter { static class viewholder { public textview nametext; public imageview imagethumbnail; } cursor cursor; public mycustomcurseradapter(context context, cursor c, int flags) { super(context, c, flags); // todo auto-generated constructor stub } @override public void bindview(view view, context arg1, cursor cursor) { viewholder holder = (viewholder)view.gettag(); int pathcol = cursor.getcolumnindex(newpicsqlitehelper.column_path); string imageinsd = cursor.getstring(pathcol); file imgfile = new file(imageinsd); if(imgfile.exists()){ int namecol = cursor.getcolumnindex(newpicsqlitehelper.column_pic_name); string name = cursor.getstring(namecol); if (name != null) holder.nametext.settext(name); imagetask task = new imagetask(holder.imagethumbnail); task.execute(imgfile); } } @override public view newview(context arg0, cursor cur, viewgroup parent) { layoutinflater inflater = layoutinflater.from(parent.getcontext()); view view = inflater.inflate(r.layout.new_pic_item, parent, false); viewholder holder = new viewholder(); holder = new viewholder(); holder.nametext = (textview) view.findviewbyid(r.id.pic_name_entry); holder.imagethumbnail = (imageview) view.findviewbyid(r.id.pic_thumbnail); // tag can object, happens viewholder view.settag(holder); return view; } private class imagetask extends asynctask<file, void, bitmap>{ private final weakreference <imageview> imageviewreference; public imagetask(imageview imageview) { imageviewreference = new weakreference <imageview> (imageview); } @override protected bitmap doinbackground(file... params) { string path = params[0].getabsolutepath(); return decodesampledbitmapfromresource(path,75,75); } @override protected void onpostexecute(bitmap result) { if (imageviewreference != null) { imageview imageview = imageviewreference.get(); if (imageview != null) { if (result != null) { imageview.setimagebitmap(result); imageview.setvisibility(imageview.visible); } else { imageview.setvisibility(imageview.invisible); } } } } private bitmap decodesampledbitmapfromresource(string orgimagepath, int reqwidth, int reqheight) { } private int calculateinsamplesize(bitmapfactory.options options, int reqwidth, int reqheight) { } }
i think probable reason thats taking time because images of @ least 1 mb size further can change thumbnail , retrieve , if still taking time put lazy downloading done when take image server(basically loads text , shows image when image)
Comments
Post a Comment