我已經完成了使用SQLite,但無法存儲這些值。我通過ListView
檢索了這個值。任何人都可以幫忙嗎?我對這個項目感到震驚。如何在數據庫中存儲經緯度詳細信息並在ListView中查看詳細信息
package com.mahesh.map2;
public class history extends ListActivity {
//private static final String DATABASE_TABLE = null;
private ArrayList<String> results = new ArrayList<String>();
// private static final String DATABASE_TABLE = "locations";
private static String DBNAME = "locationmarkersqlite";
/** Field 1 of the table locations, which is the primary key */
public static final String FIELD_ROW_ID = "_id";
/** Field 2 of the table locations, stores the latitude */
public static final String FIELD_LAT = "lat";
/** Field 3 of the table locations, stores the longitude*/
public static final String FIELD_LNG = "lng";
/** Field 4 of the table locations, stores the zoom level of map*/
public static final String FIELD_ZOOM = "zom";
/** A constant, stores the the table name */
private static final String DATABASE_TABLE = "locations";
/** An instance variable for SQLiteDatabase */
private SQLiteDatabase mDB;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
openAndQueryDatabase();
displayResultList();
}
private void displayResultList() {
TextView tView = new TextView(this);
tView.setText("This data is retrieved from the database and only 4 " +
"of the results are displayed");
getListView().addHeaderView(tView);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results));
getListView().setTextFilterEnabled(true);
}
private void openAndQueryDatabase() {
try {
LocationsDB dbHelper = new LocationsDB(this.getApplicationContext());
mDB = dbHelper.getWritableDatabase();
//double latitude;
//double longitude;
Cursor c = mDB.query("locations", new String[]{
"latitude", "longitude"}, null, null,
null, null, null);
if (c != null) {
if (c.moveToFirst()) {
do {
// String title = c.String(c
// .getColumnIndex("title"));
// String description = c.String(c
// .getColumnIndex("description"));
int latitude = (int) (c.getDouble(c
.getColumnIndex("latitude")) * 1E6);
int longitude = (int) (c.getDouble(c
.getColumnIndex("longitude")) * 1E6);
results.add("FIELD_LNG" + latitude + ",FIELD_LAT " + longitude);
}while (c.moveToNext());
}
}
} catch (SQLiteException e) {
Log.e(getClass().getSimpleName(), "Could not create or Open the database");
} finally {
if (mDB != null)
mDB.execSQL("DELETE FROM " + DATABASE_TABLE);
mDB.close();
}
}
}
你在哪裏創建數據庫? – zozelfelfo