0

データベースに4行の緯度があり、そのすべての行を取得したいと思います。でCafeDataSourceクエリを実行し、に設定しましたArrayList<HashMap<String, Object>>。ループで使用すると、TopActivity4行すべてをクエリできます。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);
}
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 に答える