我有一个列表视图,每个列表项包含由数据库填充并包含两个按钮的相关视图。 当列表视图项中的按钮之一被按下时,我需要在列表视图中获得该行的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