有并发症,这与Android的getListAdapter? [英] Have complication with getListAdapter Android?

查看:259
本文介绍了有并发症,这与Android的getListAdapter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从SQLite数据库获取经纬度数据。

I want to get latitude and longitude data from sqlite database.

所以我用这个code以下,但在 getListAdapter(有问题)。它说,我必须创建 getListAdapter()的方法。我在寻找在网络上,但对于没有例如 getListAdapter()方法。

So i use this code below, but there is a problem in getListAdapter(). It say that i must create 'getListAdapter()' method. I'm searching on the net, but there is no example for getListAdapter() method.

可以解决我的code。所以,如果我点击的项目它会给我lat和长数据从我的数据库。

Can you fix my code. So if i click the item it will give me the lat and long data from my database.

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);

}

顺便说一句,这是来自我的$ P $

推荐答案

您不需要扩展ListActivity。你只需要找到ListView和调用其getAdapter()方法。

You do not need to extend ListActivity. You simply need to find the listview and call its getAdapter() method.

下面是你更新code。

Here is your updated code.

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的getListAdapter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆