【发布时间】:2011-11-27 14:46:27
【问题描述】:
我想从 sqlite 数据库中获取经纬度数据。
所以我使用下面的这段代码,但是getListAdapter() 有问题。它说我必须创建 'getListAdapter()' 方法。我在网上搜索,但是没有getListAdapter()方法的例子。
你能修复我的代码吗?因此,如果我单击该项目,它将为我提供数据库中的经纬度数据。
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
//TODO Auto-generated method stub
String selectedItem = (String) getListAdapter().getItem(position);
String query = "SELECT lat, long FROM hoteltbl WHERE name = '" + selectedItem + "'";
SQLiteDatabase dbs = dbHotelHelper.getReadableDatabase();
Cursor result = dbs.rawQuery(query, null);
result.moveToFirst();
double lat = result.getDouble(result.getColumnIndex("lat"));
double longi = result.getDouble(result.getColumnIndex("long"));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&saddr=&daddr="+lat+","+longi));
startActivity(intent);
}
顺便说一下,这是my previous question的问题
【问题讨论】:
-
在
ListActivity,你可以简单地使用getListAdapter();在ListView,可以使用your_listview_name.getAdapter()
标签: android sqlite listview listadapter onitemclicklistener