naeemgik
naeemgik

Reputation: 2272

How to identify button click in getChildView of ExpandableListView in android

I am building ExpandableListView in my android app. I have made child xml layout that repeats upto specific numbers. I have a Delete Button in my xml layout with id set in xml as btnDelete. By clicking delete button I want to delete specific child.

e.g:

Group:

Child 1         Delete
Child 2         Delete
Chile 3         Delete

Now my problem is that how to identify that which child delete button is clicked. As all delete buttons have same ID in my xml layout. Please suggest me a solution.

Upvotes: 3

Views: 1142

Answers (1)

Shade
Shade

Reputation: 10001

In your adapter, where you inflate your row layout, you can set a tag (with the setTag () method) to each delete button. The tag can be the row position that this delete button corresponds to.

Later, when someone clicks the button, in the onClickListener, you get the button tag (with v.getTag ()), parse it to integer and delete the row at that position.

Upvotes: 2

Related Questions