【问题标题】:How to identify button click in getChildView of ExpandableListView in android如何识别android中ExpandableListView的getChildView中的按钮点击
【发布时间】:2013-03-21 12:31:21
【问题描述】:

我正在我的 android 应用程序中构建 ExpandableListView。我制作了重复特定数字的子 xml 布局。我的 xml 布局中有一个删除按钮,其中 xml 中的 id 设置为 btnDelete。通过单击删除按钮,我想删除特定的孩子。

例如:

组:

Child 1         Delete
Child 2         Delete
Chile 3         Delete

现在我的问题是如何识别单击了哪个子删除按钮。因为所有删除按钮在我的 xml 布局中都有相同的 ID。请给我一个解决方案。

【问题讨论】:

    标签: android expandablelistview baseadapter


    【解决方案1】:

    在您扩展行布局的适配器中,您可以为每个删除按钮设置一个标签(使用setTag () 方法)。标记可以是这个删除按钮对应的行位置。

    稍后,当有人单击按钮时,在onClickListener 中,您将获得按钮标记(带有v.getTag ()),将其解析为整数并删除该位置的行。

    【讨论】:

    • 谢谢,是的。我完全不知道 setTag() 和 getTag() 的使用 :)
    • @Shade 在这种情况下如何接收组位置!有什么建议吗?
    猜你喜欢
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 2023-01-28
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 2012-07-23
    相关资源
    最近更新 更多