android - ListView does not change elements at scrolling -
i have several markers on google map , in each marker listview several entries. each entry can liked user , if has liked, there stored entry in sqlite database marker id, entry id , if has liked (1) or took (0) , activity reloaded. want filled heart shown below each list item user has liked. problem is: if there many entries, there randomly filled hearts, if user liked 1 entry. these falsely filled hearts appear @ scrolling assume, listview not update elements @ scrolling... here code:
@override public view getview(final int position, view convertview, viewgroup parent) { final listcell cell; if (convertview == null) { convertview = inflater.inflate(r.layout.pinboard_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(); } cell.position = position; //listen-items mit entsprechenden elementen aus dem heruntergeladenen array befüllen try { jsonobject jsonobject = this.dataarray.getjsonobject(position); cell.likes.settext(jsonobject.getstring("likes")); cell.note.settext(jsonobject.getstring("note")); cell.entryid = jsonobject.getstring("id"); string img = jsonobject.getstring("image"); string urlforimageinserver = baseurlforimage + img; picasso.with(context) .load(urlforimageinserver) .placeholder(r.drawable.progress_animation) .error(r.drawable.no_picture) .into(cell.img); objectid = ""+cell.entryid; dbh = new dbhelper(context); cursor = getlikes(dbh); cursor.movetofirst(); if (cursor.movetofirst()) { { if (integer.parseint(cursor.getstring(2)) == 1) { cell.likeimage.setimageresource(r.drawable.heart_filled); } else { cell.likeimage.setimageresource(r.drawable.heart); } } while(cursor.movetonext()); } else { cursor.close(); } 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 int position; public string entryid; } public cursor getlikes(dbhelper dbh) { dbase = dbh.getreadabledatabase(); string columns[] = {dbh.likes_markerid, dbh.likes_entryid, dbh.likes_like}; string selection = dbh.likes_markerid + " ? , " + dbh.likes_entryid + " ? "; string args[] = {markerid.tostring(), objectid}; cursor cursor = dbase.query(dbh.table_likes, columns, selection, args , null, null, null, null); return cursor; }
if there no likes make sure set disable heart image explictly. right seems trying set inside do while loop
, if flow doesn't goes inside loop, recycled view used may or may not have disabled heart.
Comments
Post a Comment