我想用我的ListView上點擊的項目替換我的EditTexts。我用光標沿着ListView上的項目移動。但是,即使當我點擊它上面的第二個項目時,第一個項目也會顯示出來。我做錯了什麼?爲什麼我的光標不能在我的ListView中工作?
這裏是我的ListView onItemClicked代碼:
lv_people_info.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
people_info2 = new ArrayList<String>();
Cursor cursor2 = db.query(PeopleEntry.TABLE_NAME,// Table
allColumns, // The columns to return
null, // The columns for the WHERE clause
null, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
null, // The sort order
null); // Limits the number of rows returned by the query
cursor2.moveToFirst();
while (!cursor2.isAfterLast()) {
people_info2.add(cursor2.getString(1));
people_info2.add(cursor2.getString(2));
people_info2.add(cursor2.getString(3));
et_name.setText(people_info2.get(0));
et_amount.setText(people_info2.get(1));
et_description.setText(people_info2.get(2));
cursor2.moveToNext();
}
cursor2.close();
}
});
這是當我點擊ListView中的第二行會發生什麼:
這段代碼應該顯示**總是最後一個**表項後**任意一行點擊** – Selvin
@Selvin第一個,實際上。視圖是從數組開頭的內容設置的。 – njzk2
是啊,你是對的...整個問題是沒有'int position,long id'傳遞給'onItemClick'回調函數 – Selvin