我在数据库中有 4 行纬度,我想获取它的所有行。在CafeDataSource
我查询它并将其设置为ArrayList<HashMap<String, Object>>
. 当我TopActivity
在for
循环中使用它时,我可以查询所有 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);
}