我有一個列表視圖,每個列表項包含由數據庫填充幷包含兩個按鈕的相關視圖。 當列表視圖項中的按鈕之一被按下時,我需要在列表視圖中獲得該行的ID。換句話說,我試圖找到onItemClickListener()的onItemClick方法中的最後一個參數,它會返回整個項目的點擊。不過,我只是在ListView項目中聽按鈕,所以我無法使用onItemClickListener()。Android:得到按鈕點擊時的列表視圖行的ID
當我按一下按鈕
public void plusClick(View v)
{
//get the row the clicked button is in
RelativeLayout vwParentRow = (RelativeLayout)v.getParent();
//i need to get the id of this RelativeLayout item in the list view
TextView child = (TextView)vwParentRow.getChildAt(2);
Button btnChild = (Button)vwParentRow.getChildAt(1);
int c = Color.CYAN;
vwParentRow.setBackgroundColor(c);
vwParentRow.refreshDrawableState();
}
我已經被調用該方法,需要找到相對佈局,我可以通過屁股ARG爲
public Cursor getRow(long rowId) {
String where = KEY_ROWID + "=" + rowId;
Cursor c = db.query(true, DATABASE_TABLE, ALL_KEYS,
where, null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
創建一個新的ID光標contiain數據在此列表視圖項
如何爲每個按鈕設置「OnClickListener」? – 2014-08-31 08:21:50
「創建一個新的遊標,在此列表視圖項目中添加數據」... umm ...爲什麼需要新的遊標?你不使用'CursorAdapter'嗎?如果不是,我強烈建議你這樣做。聽起來你正試圖在這裏重新發明輪子。 – 2014-08-31 08:27:02
按鈕當前設置與XML的android:的onClick =「plusClick」 – sam 2014-08-31 08:30:37