Get Data From Sqlite Database To Intent Through "onitemclick" On Item In Listview Android
I really need your help. I have a database with latitude and longitude data, here the example: id_____name_____lat_________long 1_____hotel one___6.1234______-106.12345 2____hotel
Solution 1:
First, only one query is necessary. No need to query your table twice. Second, you need to adapt your query with parameters from your selection:
@OverrideprotectedvoidonListItemClick(ListView listView, View view, int position, long id) {id) {
StringselectedItem= (String) getListAdapter().getItem(position);
Stringquery="SELECT lat, long FROM hoteltbl WHERE name = '" + selectedItem + "'";
SQLiteDatabasedbs= dbHotelHelper.getReadableDatabase();
Cursorresult= dbs.rawQuery(query, null);
result.moveToFirst();
doublelat= result.getDouble(result.getColumnIndex("lat"));
doublelong= result.getDouble(result.getColumnIndex("long"));
....
This code was written in the StackOverflow editor, it might not work as such, but will give you an idea.
(Also, don't add suffixes "_var", or "_long" to your variables, it's not necessary in a strongly-typed language like Java)
Post a Comment for "Get Data From Sqlite Database To Intent Through "onitemclick" On Item In Listview Android"