android - Issue with custom SimpleCursorAdapter -
android - Issue with custom SimpleCursorAdapter -
i'm trying fill grid view using info db cursor using custom simplecursoradapter. cursor has info (i checked), nil shown in gridview, , getview() method not called.
anybody can help? why getview() not called?
thanks
activity
dbadapter = new dbadapter(this); dbadapter.open(); cursor c; c = dbadapter.fetchpclist(); startmanagingcursor(c); string[] = new string[] {}; int[] = new int[] {}; gridview gridview = (gridview) findviewbyid(r.id.gridview); gridview.setadapter(new pciconadapter(this, r.layout.pc_icon, c, from, to)); c.close(); dbadapter.close();
adapter
public class pciconadapter extends simplecursoradapter { private final context mcontext; private final int mlayout; private final cursor mcursor; private final int mpcidindex; private final int mclassnameindex; private final layoutinflater mlayoutinflater; private final class viewholder { public textview pc_id_view; public textview clas_name_view; } public pciconadapter(context context, int layout, cursor c, string[] from, int[] to) { super(context, layout, c, from, to); this.mcontext = context; this.mlayout = layout; this.mcursor = c; this.mpcidindex = mcursor.getcolumnindex(dbadapter.key_pc_lm_id); this.mclassnameindex = mcursor.getcolumnindex(dbadapter.key_pc_clas_name); this.mlayoutinflater = layoutinflater.from(mcontext); } public view getview(int position, view convertview, viewgroup parent) { if (mcursor.movetoposition(position)) { viewholder viewholder; if (convertview == null) { convertview = mlayoutinflater.inflate(mlayout, null); viewholder = new viewholder(); viewholder.pc_id_view = (textview) convertview.findviewbyid(r.id.pc_id); viewholder.clas_name_view = (textview) convertview.findviewbyid(r.id.clas_name); convertview.settag(viewholder); } else { viewholder = (viewholder) convertview.gettag(); } string pc_id = mcursor.getstring(mpcidindex); string clas_name = mcursor.getstring(mclassnameindex); viewholder.pc_id_view.settext(pc_id); viewholder.clas_name_view.settext(clas_name); } homecoming convertview; } }
i had same problem. using arrayadapter , changed simplecursoradapter, doesn't show on screen.
i removed
c.close(); dbadapter.close();
and working fine.
android gridview simplecursoradapter
Comments
Post a Comment