android - Get String Array from Cursor -
i have sqlite database 45 different entries, each with:
public static final string table = "table"; public static final string column_id = "_id"; public static final string column_hour = "hour"; public static final string column_week = "week"; public static final string column_day = "day"; public static final string column_name = "name"; public static final string column_description = "description"; public static final string column_colour = "colour"; public static final string column_room = "room"; now want read out all. following:
public cursor fetchallsubject(){ cursor mcursor = database.query(true, table, new string[] { column_id, column_hour, column_week, column_day, column_name, column_description, column_colour, column_room},null , null, null, null, null, null); if (mcursor != null) { mcursor.movetofirst(); } return mcursor; } in other class have code read out:
dao = new dao(this); cursor subjectlist = dao.fetchallsubject(); now want have each entry array id, hour, week, ... have no idea how that. first try following:
arraylist<string> mo1h = new arraylist<string>(); subjectlist.movetofirst(); while(!subjectlist.isafterlast()) { mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_id))); mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_hour))); mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_week))); mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_day))); mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_name))); mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_description))); mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_colour))); mo1h.add(subjectlist.getstring(subjectlist.getcolumnindex(dao.column_room))); subjectlist.movetonext(); } but in mo1h, , dont know how devide it. best have string[] each. has idea? thanks!
you can create on bean class , create 1 arraylist (collection class)
public class bean { public bean(); string id, hour, week, day, name, description, color, room; } now create list of bean
arraylist<bean> mo1h = new arraylist<bean>(); subjectlist.movetofirst(); while(!subjectlist.isafterlast()) { bean b = new bean(); b.id = subjectlist.getstring(subjectlist.getcolumnindex(dao.column_id)); b.hour =subjectlist.getstring(subjectlist.getcolumnindex(dao.column_hour)); ... ... // column mo1h.add(b); }
Comments
Post a Comment