我长时间陷入困境。我的列表视图中有按钮。我能够处理按钮上的点击事件但我没有得到该按钮的位置,因为它无法检索项目点击对象。
@Override
public View getView(int p, View v, ViewGroup arg2) {
ViewHolder holder = null;
if (v == null) {
v = li.inflate(R.layout.data, null);
holder = new ViewHolder();
holder.button1 = v.findViewByid("button1"); //this is button which i want to handle its onclick to get the position of button
holder.button2 = v.findViewByid("button1");
holder.button1.setOnClickListener(new View.OnClickListener() {@
Override
public void onClick(View v) {
}
});
holder.button2.setOnClickListener(new View.OnClickListener() {@
Override
public void onClick(View v) {
}
});
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
return v;
}
public static class ViewHolder {
public Button button1;
public Button button2;
}
答案 0 :(得分:1)
使用item
为clicked
的 int position ,
这将帮助您在按下按钮时执行操作!