Android: sqlite returning information from all rows containing a similar value in one row -
i trying have user select value, search database value, , return information rows containing value.
i tried following, not sure how return results correctly other activity viewed user.
cursor c = ourdatabase.rawquery("select * favoritetable " + key_favname + " = '" + favoriteworkoutname + "'", null); i tried this, int row specifying key_row want grab data when querying. example, user enters name of favorite workout, searches database rows containing name, , returns key_rows 1, 2, , 3 (which correspond exercise, reps, etc). however, returns 1 row value 1 row.
int row = 1; cursor c = ourdatabase.rawquery("select * favoritetable " + key_favname + " = '" + favoriteworkoutname + "'", null); do{c.movetonext(); string data = c.getstring(row); return data; }while (row <= 3); any suggestions?
**edit:
i had had in activity that. here have there. however, getting error, , asks me either "change type of listcursor cursor", is...or "change return type of 'getfavoritedata' cursor", is.
also, when not have error, i'm not sure how use returned data , insert textview. not allow me settext(listcursor).
i ideally need information each returned row separate string can display them way need in textviews.
in activity:
string favoriteworkoutname = cfdname.gettext().tostring(); exercisedatabase choosefavorite = new exercisedatabase(workmeoutactivity.this); try { choosefavorite.open(); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } cursor listcursor = choosefavorite.getfavoritedata(favoriteworkoutname); choosefavorite.close(); in dbhelper class:
public cursor getfavoritedata(string favoriteworkoutname){ return ourdatabase.rawquery("select * favoritetable " + key_favname + " = '" + favoriteworkoutname + "'", null); }
i think misunderstood getstring() method. have look:
public abstract string getstring (int columnindex) since: api level 1 returns value of requested column string.
the result , whether method throws exception when column value null or column type not string type implementation-defined. parameters columnindex zero-based index of target column. returns value of column string. so, if pass 1,2 or 3 inside c.getstring(row) gives value of 1 column(with index 1,2 or 3) specific row.
you can use c.getstring(c.getcolumnindex(column_name)) if not sure index of column , want it's name.
now think want retrieve value of columns(say first 3 column value of row) first few matching rows(like 3 rows) , use them if use:
cursor c = ourdatabase.rawquery("select * favoritetable " + key_favname + " = '" + favoriteworkoutname + "'", null); string fcv=""; string scv=""; string tcv=""; if(c.getcount() == 0) { //no data found } else { int i=0; c.movetofirst(); { fcv = fcv + c.getstring(0)); //or use fcv = fcv + c.getstring(c.getcolumnindex(name of first column))); scv = fcv + c.getstring(1)); tcv = fcv + c.getstring(2)); i++; } while (c.movetonext() && i<3); c.close(); use value of strings according need :)
Comments
Post a Comment