Android 如果行ID与listView项ID匹配,则显示SQLite行值

Android 如果行ID与listView项ID匹配,则显示SQLite行值,android,sqlite,listview,Android,Sqlite,Listview,以下是我的设想: 假设我有一个SQLite表,其中显示了一些ID为且当然是自动递增的行 public static final String DataTableName = "jobsTable"; public static final String ColID = "ID"; public static final String ColPlace = "placeName"; public static final String ColPosition = "posi

以下是我的设想:

假设我有一个SQLite表,其中显示了一些ID为且当然是自动递增的行

public static final String DataTableName = "jobsTable";
    public static final String ColID = "ID";
    public static final String ColPlace = "placeName";
    public static final String ColPosition = "position";
    public static final String ColStartingTime = "startingTime";
    public static final String ColHours = "hours";
    public static final String ColAddress = "address";
    public static final String ColPhoneNumber = "phoneNumber"; 
“placeName”、“position”和“startingTime”用于填充listView单元格,如下所示:

现在我的问题是,如何显示ID与列表项ID匹配的表行的值?因此,当用户按下某个项目时,将显示共享相同ID的表行。谢谢

以下是我迄今为止尝试过的方法(仅使用onItemClickedListner方法),但我知道我没有正确检索数据

@Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


                // get the IDs of each column in the database
                String [] IDs = activity.getAllColumnsIDs().toArray(
                        new String[activity.getAllColumnsIDs().size()]);

                // loop throught the IDs and see if they match the listView
                // item ids. if yes, display the detail
                DataBaseHelper summerJobDB;
                summerJobDB = new DataBaseHelper(activity);
                for (int i = 0; i >= IDs.length; i++) {
                    if (i == id) {


                        Cursor res = summerJobDB.getAllData();
                        if (res.getCount() ==0){
                            // show some message
                            showMessage("Error", "Nothing found");
                            return;
                        }
                        StringBuffer buffer = new StringBuffer();
                        // append the values from the database to the buffer.
                        // this is based on the index number of the columns
                        while (res.moveToNext()) {
                            buffer.append(res.getString(1)+ "/" + res.getString(2) +"\n");
                            buffer.append("Starts on " + res.getString(3)+"\n\n");
                            buffer.append("Address: \n"+ res.getString(5)+"\n\n");
                            buffer.append("Phone: \n"+ res.getString(6)+"\n\n");
                            buffer.append("Hours: \n"+ res.getString(4)+"\n\n");
                        }
                        // show all data here

                        showMessage("Data",buffer.toString());

                    }
                }

            }
@覆盖
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//获取数据库中每个列的ID
String[]IDs=activity.getAllColumnsIDs().toArray(
新字符串[activity.getAllColumnsIDs().size()];
//循环遍历ID,查看它们是否与listView匹配
//项目ID。如果是,则显示详细信息
数据库数据库;
summerJobDB=新数据库助手(活动);
对于(int i=0;i>=IDs.length;i++){
如果(i==id){
Cursor res=summerjobd.getAllData();
如果(res.getCount()==0){
//显示一些消息
showMessage(“错误”,“未找到任何内容”);
返回;
}
StringBuffer=新的StringBuffer();
//将数据库中的值追加到缓冲区。
//这是基于列的索引号
while(res.moveToNext()){
append(res.getString(1)+“/”+res.getString(2)+“\n”);
append(“开始于”+res.getString(3)+”\n\n”);
buffer.append(“地址:\n”+res.getString(5)+”\n\n”);
buffer.append(“Phone:\n”+res.getString(6)+”\n\n”);
buffer.append(“小时:\n”+res.getString(4)+“\n\n”);
}
//在此处显示所有数据
showMessage(“Data”,buffer.toString());
}
}
}