gpt4 book ai didi

java - 安卓 : get id of listview row when button clicked

转载 作者:行者123 更新时间:2023-12-01 12:35:58 26 4
gpt4 key购买 nike

我有一个 ListView ,其中包含每个列表项的相对 View ,这些列表项由数据库填充,并包含两个按钮。当按下 ListView 项中的按钮之一时,我需要获取 ListView 中该行的 ID。换句话说,我试图找到与 onItemClickListener() 的 onItemClick 方法中的最后一个参数相同的东西,这将返回整个项目的点击。但是我只是在监听 ListView 项中的按钮,所以我无法使用 onItemClickListener()。

当我单击按钮时,会调用此方法

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();
}

它需要找到我可以传递 ass arg 的相对布局的 id

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;
}

创建一个包含此 ListView 项中的数据的新光标

最佳答案

试试这个代码:

private OnItemClickListener itemClickListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> av, View v, int position,
long id) {
// write your logic here
// position starts from 0
// id starts from 1

}
};

关于java - 安卓 : get id of listview row when button clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25590139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com