Android使用arraylist

时间:2015-06-16 05:16:58

标签: java android sqlite

我使用arraylist从数据库中获取数据,但是一些double值会转换为舍入值。

public ArrayList<HashMap<String, String>> getTrackList() {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    String selectQuery = "SELECT * FROM TRACK";

    ArrayList<HashMap<String, String>> trackList = new ArrayList<HashMap<String, String>>();

    trackList.clear();

    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {
            HashMap<String, String> track = new HashMap<String, String>();
            track.put("LATITUDE", cursor.getString(cursor.getColumnIndex("LATITUDE")));
            track.put("LONGITUDE", cursor.getString(cursor.getColumnIndex("LONGITUDE")));
            track.put("DATE", cursor.getString(cursor.getColumnIndex("DATE")));
            track.put("SPEED", cursor.getString(cursor.getColumnIndex("SPEED")));
            track.put("ACCURACY", cursor.getString(cursor.getColumnIndex("ACCURACY")));
            track.put("PROVIDER", cursor.getString(cursor.getColumnIndex("PROVIDER")));
            track.put("DISTANCE", cursor.getString(cursor.getColumnIndex("DISTANCE")));

            trackList.add(track);
        } while (cursor.moveToNext());
    }
    jSon = new Gson().toJson(trackList);
    cursor.close();
    return trackList;
}

这里纬度,经度和距离是双倍值,距离与数据库相同,但纬度或经度不相同,假设数据库中纬度为22.8569874但返回22.857

2 个答案:

答案 0 :(得分:0)

唯一的解释是数据库中的数据格式类似于double

如果查询将其读出,则将数字四舍五入为。[/ p>

尝试将数据库中的值更改为string并将其写为:22.8569874;然后,如果您需要用于计算的数字或其他内容,则从字符串中删除"并将其转换为double

答案 1 :(得分:0)

尝试一下:

while (cr.moveToNext()) {
    cr.getString(cr.getColumnIndex("CardName"));
    Log.e("SOAP ERROR",cr.getString(cr.getColumnIndex("CardName")));
 }