ListView item with button and know what item the button was inside after click

前端 未结 3 1828
情深已故
情深已故 2021-01-16 18:00

I have a list view where items have a text view and a button. I have managed to make list view onclick and button on click work together. The problem is that when I click th

相关标签:
3条回答
  • 2021-01-16 18:32

    You can use setTag and getTag here to get the position of the Button Clicked in the ListView,

    Something like,

    button.setTag(position); // in your getView() method

    and then,

    int cur_pos = (Integer)v.getTag(); // inside onClick of Button in getView() method

    0 讨论(0)
  • 2021-01-16 18:38

    Some options:

    • You can have separate OnClickListener instances for each button.

    • You can call setTag() on your button to store arbitrary data (e.g. index or identifier) and retrieve it later with getTag()

    0 讨论(0)
  • 2021-01-16 18:43

    An other solution would be to reproduce the button click on its parent, when the user tap on the button: http://developer.android.com/reference/android/view/View.html#performClick()

    0 讨论(0)
提交回复
热议问题