android - Infinity loop. Reading data from database and comparing them to with an if statment -
my english little rusty, try explain want do.
i have database , 5 rows in it. trying this:
- read n rows database.
- assign data database variables
- check if variables belongs condition
if(((szerokosc<=a)&&(szerokosc>=b)) && ((dlugosc>=c)&&(dlugosc<=d)))
- if yes, display (opis)
- if not, display(brak danych)
- if end of rows go first
- if there exists next row, go it,
i want on , on again;
public void onlocationchanged(location location) { showlocation(location); showadditionalinfo(location); if(savedlocation == null) savedlocation = locationmanager.getlastknownlocation(locationmanager.gps_provider); databasehelper zb = new databasehelper(getapplicationcontext()); double szerokosc = location.getlatitude(); double dlugosc = location.getlongitude(); cursor k = zb.dajcos(); string lokalizacja = "jestes na: "; while(k.movetonext()) { nazwa = k.getstring(0); szmax= k.getdouble(1); szmin= k.getdouble(2); dlmin= k.getdouble(3); dlmax= k.getdouble(4); opis = k.getstring(5); a=szmax; b=szmin; c=dlmin; d=dlmax; if(k.movetonext()==false){k.movetofirst();} } if(((szerokosc<=a)&&(szerokosc>=b)) && ((dlugosc>=c)&&(dlugosc<=d))) { lokalizacja =nazwa+opis; } else { lokalizacja ="brak danych"; } tvlokalizacja.settext(lokalizacja); }
this public cursor dajcos()
public cursor dajcos() { string[] kolumny={"nazwa","szmax","szmin","dlmin","dlmax","opis"}; sqlitedatabase db = getreadabledatabase(); cursor kursor = db.query("obiekty", kolumny, null, null, null, null, null); return kursor; }
i dont know how explain better. try describe in way.
in database have 5 records each of them include coordinates. example: position corresponds coordinates second row , want display in "zone1", move ten meters away , position don't match coordinates in row want display "no data", move fifteen meters away fourth row coordinates match position , display in "zone2".
i hope understand mean , me. thank you.
i have loop:
k.movetofirst(); //iterate on rows (int = 0; < k.getcount(); i++) { nazwa = k.getstring(0); szmax= k.getdouble(1); szmin= k.getdouble(2); dlmin= k.getdouble(3); dlmax= k.getdouble(4); opis = k.getstring(5); a=szmax; b=szmin; c=dlmin; d=dlmax; wypisz +=i+nazwa+"-"+a+"-"+opis+"\n"; tvbaza.settext(wypisz); k.movetonext(); }
loop execute 5 times because have 5 rows in database. want change execute on , on again.
Comments
Post a Comment