android - Updating ListView to strikethough item on click -
i using cursoradapter listview , cursor getting data sqlite database. have function called renderlist() call every time update database new item list or if set checked value of row 1 (this add new item or strikethough item name).
private void renderlist(){ string showwhere = show_checked ? null : dbhelper.c_checked + "= '0' "; try { db = dbhelper.getreadabledatabase(); cursor = db.query(dbhelper.table, null, showwhere, null, null, null, dbhelper.c_id + " desc"); grocerieslist = (listview)findviewbyid(r.id.listview1); adapter = new groceryadapter(this, cursor); adapter.newview(getapplicationcontext(), cursor, grocerieslist); grocerieslist.setadapter(adapter); grocerieslist.setonitemclicklistener(itemlistener); } catch (exception e) { log.d(tag, "renderlist error: ",e); } }
this reset list, if click item way down listview reset listview top position. i'm missing how update listview, , database in efficient, , usable way?
public class groceryadapter extends cursoradapter { private final layoutinflater minflater; public groceryadapter(context context, cursor cursor) { super(context, cursor, true); minflater = layoutinflater.from(context); // mcontext = context; } @override public void bindview(view view, context context, cursor cursor) { twolinelistitem listitem = (twolinelistitem)view; textview t1 = listitem.gettext1(); textview t2 = listitem.gettext2(); t1.settext(cursor.getstring(cursor.getcolumnindex(dbhelper.c_grocery))); t2.settext("added by: wes"); t1.settag(cursor.getint(cursor.getcolumnindex(dbhelper.c_id))); t2.settag(cursor.getint(cursor.getcolumnindex(dbhelper.c_checked))); if (cursor.getint(cursor.getcolumnindex(dbhelper.c_checked)) == 1 ) { t1.setpaintflags(t1.getpaintflags() | paint.strike_thru_text_flag); listitem.setbackgroundcolor(0xeecccccc); } else { t1.setpaintflags(t1.getpaintflags() & (~paint.strike_thru_text_flag) ); listitem.setbackgroundcolor(0x00000000); } } @override public view newview(context context, cursor cursor, viewgroup parent) { final view view = minflater.inflate(r.layout.grocery_list_item, parent, false); return view; } }
Comments
Post a Comment