如何在列表视图中单击按钮后获取按钮的位置

时间:2013-07-15 18:35:01

标签: android android-listview

我长时间陷入困境。我的列表视图中有按钮。我能够处理按钮上的点击事件但我没有得到该按钮的位置,因为它无法检索项目点击对象。

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

1 个答案:

答案 0 :(得分:1)

使用itemclicked int position

这将帮助您在按下按钮时执行操作!