データベースに4行の緯度があり、そのすべての行を取得したいと思います。でCafeDataSource
クエリを実行し、に設定しましたArrayList<HashMap<String, Object>>
。ループで使用すると、TopActivity
4行すべてをクエリできます。for
ただし、4つの行すべてに、最後の行の値が1つだけあります。例:私のデータベース(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;
}
TopActivity
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);
}