我正在尝试为密码管理器创建一个列表视图,该列表视图将使用数据库中的项目填充列表视图,当有人单击它时,它将返回primaryid ....我看过其他示例,但无法正确完成... .这是我到目前为止所做的......我能够填充列表视图但无法处理点击事件:(
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice , listItems);
SQLiteDatabase DB= null;
final String TableName = "XIBEAT_PASSWORDS";
String DBname="Xibeat_Crypto_Knight_Vault";
try {
DB = this.openOrCreateDatabase(DBname, MODE_PRIVATE, null);
DB.execSQL("CREATE TABLE IF NOT EXISTS " + TableName + " ('_id' INTEGER PRIMARY KEY AUTOINCREMENT,HOST TEXT, URL TEXT, PASSWORD TEXT, NOTES TEXT, TAG TEXT, TIME TEXT, DATE TEXT, EXPIRE TEXT, EDITED TEXT, STRENGTH TEXT, REASON TEXT);");
Cursor c = DB.rawQuery("SELECT * FROM " + TableName , null);
int host= c.getColumnIndex("HOST");
String title="";
c.moveToFirst();
if(c!=null)
{
while (c.moveToNext()){
title = c.getString(host);
//Toast(title);
listItems.add(title);
}
}
final ListView passList=(ListView)findViewById(R.id.passlist);
passList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems));
//===============ONCLICK LISTENER+=========
passList.setOnItemClickListener(new OnItemClickListener()
{public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
}});
} finally {
if (DB != null)
DB.close();
}
}