0

我在数据库中有 4 行纬度,我想获取它的所有行。在CafeDataSource我查询它并将其设置为ArrayList<HashMap<String, Object>>. 当我TopActivityfor循环中使用它时,我可以查询所有 4 行。但所有 4 行只有最后一行的一个值。例如,我的数据库 (1,2,3,4) 但我的结果 (4,4,4,4)。

我有 log(db)getArrCursor()的价值,它工作正常。

我在循环中有 log(number) 以for获取值,但它显示我全部都是最后一行。

如何查询所有内容和不同的行?

CafeDataSource

public ArrayList<HashMap<String, Object>> getArrCursor(){
    arrCursor = new ArrayList<HashMap<String,Object>>();
    HashMap<String, Object> map;
    Cursor cursor = database.rawQuery("SELECT * FROM "+CafeDbOpenHelper.TABLE_CAFE, null);

    if(cursor != null){
        while(cursor.moveToNext()){
            map = new HashMap<String, Object>();
            map.put(CafeDbOpenHelper.CAFE_TITLE, cursor.getString(cursor.getColumnIndex(CafeDbOpenHelper.CAFE_TITLE)));
            map.put(CafeDbOpenHelper.CAFE_THUMB, cursor.getString(cursor.getColumnIndex(CafeDbOpenHelper.CAFE_THUMB)));
            map.put(CafeDbOpenHelper.CAFE_LATITUDE, cursor.getDouble(cursor.getColumnIndex(CafeDbOpenHelper.CAFE_LATITUDE)));
            map.put(CafeDbOpenHelper.CAFE_LONGITUDE, cursor.getDouble(cursor.getColumnIndex(CafeDbOpenHelper.CAFE_LONGITUDE)));
            Log.i("db", "" +cursor.getDouble(cursor.getColumnIndex(CafeDbOpenHelper.CAFE_LATITUDE)));
            arrCursor.add(map);
        }
    }
    return arrCursor;
}

热门活动

int position = arrCursor.size();
for (int i = 0; i < position; i++) {
    Log.i("number", "" +arrCursor.get(position -1).get(CafeDbOpenHelper.CAFE_LATITUDE));    
    double lat = (Double) arrCursor.get(position -1).get(CafeDbOpenHelper.CAFE_LATITUDE);
    double lng = (Double) arrCursor.get(position -1).get(CafeDbOpenHelper.CAFE_LONGITUDE);
    LatLng latlong = new LatLng(lat, lng);
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    Marker maker = map.addMarker(new MarkerOptions().position(latlong).title((String) arrCursor.get(position -1).get(CafeDbOpenHelper.CAFE_TITLE)));

    // Move the camera instantly to hamburg with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlong, 17));

    LinearLayout includeMap = (LinearLayout) findViewById(R.id.lin_map);
    includeMap.setVisibility(v.VISIBLE);
}
4

1 回答 1

1

PositionArray永远不会改变,但您每次都在使用它来获取。试试吧

double lat = (Double) arrCursor.get(i).get(CafeDbOpenHelper.CAFE_LATITUDE);
double lng = (Double) arrCursor.get(i).get(CafeDbOpenHelper.CAFE_LONGITUDE);

编辑

你有没有改变这条线

Marker maker = map.addMarker(new MarkerOptions().position(latlong).title((String) arrCursor.get(position -1).get(CafeDbOpenHelper.CAFE_TITLE)));

 Marker maker = map.addMarker(new MarkerOptions().position(latlong).title((String)                
    arrCursor.get(i).get(CafeDbOpenHelper.CAFE_TITLE)));

你从你的i位置开始,Array所以每次你想访问那个位置时,你都会使用i

于 2013-03-14T03:44:15.033 回答