Cursor while loop returning every value but the last

前端 未结 4 1518
旧巷少年郎
旧巷少年郎 2021-01-12 16:59

I am using a while loop to iterate through a cursor and then outputing the longitude and latitude values of every point within the database.

For some reason it is n

4条回答
  •  时光说笑
    2021-01-12 17:54

    moveToNext() has two features. It returns a boolean signifying that there is a next, but at the same time it goes ahead and moves the cursor.

    public void loadTrack() {
    SQLiteDatabase db1 = waypoints.getWritableDatabase();
    Cursor trackCursor = db1.query(TABLE_NAME, FROM, "trackidfk=1", null, null, null,ORDER_BY); 
    
        trackCursor.moveToFirst();
        do {
            Double lat = trackCursor.getDouble(2);
            Double lon = trackCursor.getDouble(1);
            //overlay.addGeoPoint( new GeoPoint( (int)(lat*1E6),  (int)(lon*1E6)));
            System.out.println(lon);
            System.out.println(lat);
        } while (trackCursor.moveToNext());
    }
    

提交回复
热议问题