我想从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。您只需要找到listview并调用其getAdapter()方法。

这是您更新的代码。

public void onItemClick(AdapterView<?> arg0, View arg1, int position,
            long arg3) {
//TODO Auto-generated method stub
ListView lv = (ListView) findViewById(R.id.YOURLISTVIEW);
String selectedItem = (String) lv.getAdapter().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);

}

关于android - Android的getListAdapter有并发症吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8286350/

10-09 19:26