我必须在数据库中找到“id”,我尝试这种方式,但我无法解决它。你可以帮帮我吗。非常感谢。
listview.setOnItemClickListener(new AdapterView.XouOnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String text = (String) listview.getItemAtPosition(arg2);
Database db = new Database(getApplicationContext());
String query = "SELECT name, id FROM tableDB WHERE name = '" + text + "'"; // I think problem is here
Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst();
id_position = cursor.getInt(cursor.getColumnIndex("id"));
go_detail();
}
});
//这部分没问题
private void go_detail(){
Intent intent = new Intent(getApplicationContext(), Detail_page.class);
intent.putExtra("id", (int) name_ids[id_position]);
startActivity(intent);
}
答案 0 :(得分:0)
我认为错误在您的go_detail
函数中。尝试添加一个参数,例如go_detail(int id_position){....}
,它不能获取没有参数的id