java - Where call cursor in Adapter Class -
i have class getallentryslistviewadapter extends baseadapter
list view in pinboardactivity
set array. want change likeimage
if there saved entry in sqlite database. call getlike
cursor in getview
way:
@override public view getview(final int position, view convertview, viewgroup parent) { final listcell cell; if (convertview == null) { convertview = inflater.inflate(r.layout.get_all_entry_list_view_cell, null); cell = new listcell(); cell.likes = (textview) convertview.findviewbyid(r.id.listviewlikes); cell.note = (textview) convertview.findviewbyid(r.id.listviewnote); cell.img = (imageview) convertview.findviewbyid(r.id.listviewimg); cell.likeimage = (imageview) convertview.findviewbyid(r.id.heartimage); convertview.settag(cell); } else { cell = (listcell)convertview.gettag(); } try { jsonobject jsonobject = this.dataarray.getjsonobject(position); cell.likes.settext(jsonobject.getstring("likes")); cell.note.settext(jsonobject.getstring("note")); string img = jsonobject.getstring("image"); string urlforimageinserver = baseurlforimage + img; new asynctask<string, void, bitmap>() { @override protected bitmap doinbackground(string... params) { //download image string url = params[0]; bitmap icon = null; try { inputstream in = new java.net.url(url).openstream(); icon = bitmapfactory.decodestream(in); } catch(malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return icon; } @override protected void onpostexecute(bitmap result) { cell.img.setimagebitmap(result); } }.execute(urlforimageinserver); //cursor called --> line causes error cursor = dbh.getlike(dbh); cursor.movetofirst(); string markerid = pinboard.markerid; if (cursor.movetofirst()) { { if (cursor.getstring(0).equals(markerid) && integer.parseint(cursor.getstring(1))== position && integer.parseint(cursor.getstring(2)) == 1) { cell.likeimage.setimageresource(r.drawable.heart_filled); } } while(cursor.movetonext()); } cursor.close(); } catch (jsonexception e) { e.printstacktrace(); } return convertview; } public static class listcell { private textview likes; private textview note; private imageview img; public imageview likeimage; public boolean touched; }
as opening pinboardactivity
following error: java.lang.nullpointerexception: attempt invoke virtual method 'android.database.cursor de.mareike.cityexplorer.dbhelper.getlike(de.mareike.cityexplorer.dbhelper)' on null object reference
am calling cursor on wrong place or cause issue? way, context set way:
public getallentryslistviewadapter(context context, cursor cursor) { super(); cursor = cursor; dbhelper dbh = new dbhelper(context); inflater=layoutinflater.from(context); }
Comments
Post a Comment