How to identify button click in getChildView of ExpandableListView in android

天涯浪子 提交于 2019-12-20 02:39:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15547610/how-to-identify-button-click-in-getchildview-of-expandablelistview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!