android - How to get field value instead of column name? -
i want fill list data cursor way:
mycursor = mydba.getallcompanies(); startmanagingcursor(mycursor); mylistadapter = new simplecursoradapter(this, r.layout.company_row, mycursor, from, to); mylistadapter.setviewbinder(view_binder); companieslistview.setadapter(mylistadapter);
i use custom viewbinder
fill 2 textviews
, 1 imageview
in each row:
private final viewbinder view_binder = new viewbinder() { /** * binds cursor column defined specified index * specified view. */ @override public boolean setviewvalue(view view, cursor cursor, int columnindex) { int viewid = view.getid(); switch (viewid) { case r.id.company_name: case r.id.company_desc: log.d(tag, "binding textview"); textview venuetext = (textview) view; venuetext.settext(cursor.getstring(columnindex)); return true; case r.id.company_icon: log.d(tag, "binding imageview"); imageview venueicon = (imageview) view; string iconname; iconname = cursor.getstring(columnindex); //here column name not field value resources resources = mycontext.getresources(); drawable drawable = resources.getdrawable(resources .getidentifier("my.package:drawable/" + iconname, null, null)); venueicon.setimagedrawable(drawable); return true; } return false; } };
my problem cursor.getstring()
method call returns column name not value of field , hundreds of rows column names.
update:
my getallcompanie
s includes movetofirst
call on cursor
still column names:
public cursor getallcompanies(){ cursor s = mydb.query(table, keys, where, null, null, null, null); s.movetofirst(); return s; }
did tried move cursor first index cursor.movetofirst();
cursor.getstring(columnindex);
?
there way, create 1 list or array hold values cursor, access data inside iterating through cursor
while(cursor.isafterlast()==false) { list.add(cursor.getstring(thestringcollumnindex); cursor.movetonext(); }
then do
iconname=list.get(columnindex);
this solution not best how ever serves purpose.
Comments
Post a Comment