android - How to getItemID from sqlite with BaseAdapter? -
i have sqlite column defined this:
public final static string s_id = "_id"; public final static string s_photopath = "photopath"; public final static string s_name = "name"; public final static string s_pos = "pos"; public final static string s_score = "score"; public final static string s_fixed = "fixed";
i'd getitemid sqlite helper class adapter class extends baseadapter. here code:
public class page1listadapter extends baseadapter { private layoutinflater adapterinflater; public cursor mcursor; tagview tag; public page1listadapter(context context, cursor cursor) { super(); mcursor = cursor; adapterinflater=layoutinflater.from(context); } @override public int getcount() { return mcursor.getcount(); } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) { tag = new tagview(); convertview = adapterinflater.inflate(r.layout.page1listview_item, null); tag.imgv = (imageview) convertview.findviewbyid(r.id.itemimage); tag.titlev = (textview) convertview.findviewbyid(r.id.itemtitle); tag.descriptionv = (textview) convertview.findviewbyid(r.id.itemtext); convertview.settag(tag); } else { tag = (tagview) convertview.gettag(); } mcursor.movetoposition(position); bitmap bmp = bitmapfactory.decodefile(mcursor.getstring(mcursor.getcolumnindex(dbhelper.s_photopath))); bitmapdrawable bmpdrawable = new bitmapdrawable(getactivity().getresources(), bmp); tag.imgv.setbackground(bmpdrawable); tag.titlev.settext(mcursor.getstring(mcursor.getcolumnindex(dbhelper.s_name))); tag.descriptionv.settext(mcursor.getstring(mcursor.getcolumnindex(dbhelper.s_pos))); return convertview; } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { log.i("mcursor.getcount() --->", string.valueof(mcursor.getcount())); mcursor.move(position); long id = mcursor.getlong(0); // <--- error here return id; } public void settag (drawable dwb, string title, string description) { tag.imgv.setbackground(dwb); tag.titlev.settext(title); tag.descriptionv.settext(description); } }
however, getitemid() error or wrong id.
how _id column value cursor?
thanks in advance!
cursor.move()
moves cursor relative amount. want absolute position, use movetoposition()
instead.
Comments
Post a Comment