首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExpandableListView -如何保持一个组的孩子突出显示?

问ExpandableListView -如何保持一个组的孩子突出显示?
EN

Stack Overflow用户
提问于 2016-02-25 19:22:31
回答 1查看 633关注 0票数 0

如何取消选中的所有其他子视图?我只想在任何时候保持一个突出的孩子。在下面的代码中,我能够高亮显示子元素,但是我在该组中选择的任何其他子元素都会被高亮显示。另外,如果我选择一个子组和切换组,那么位于相同位置的下一个组子也将被高亮显示。

代码语言:javascript
复制
 //CHILD CLICK LISTENER
 lstRoute.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

        for(int i = 0; i < parent.getChildCount(); i++)
        {
            View child = parent.getChildAt(i);
            if(child instanceof ViewGroup)
            {
                //DO NOTHING
            }else
            {
                child.setBackgroundColor(Color.TRANSPARENT);
            }
        }
        v.setBackgroundColor(Color.GREEN);
        return true;
    }
});

 //GROUP EXPANDED
lstRoute.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
    @Override
    public void onGroupExpand(int groupPosition) {

        //Only allow one group to be expanded at a time
        if (lastExpandedPosition != -1 && groupPosition != lastExpandedPosition) {
            lstRoute.collapseGroup(lastExpandedPosition);
        }
        lastExpandedPosition = groupPosition;

        //Clear all selections
        for(int i = 0; i < lstRoute.getChildCount(); i++)
        {
            View child = lstRoute.getChildAt(i);
            if(child instanceof ViewGroup) {
                child.setBackgroundColor(Color.argb(100,139,213,252)); //Light Blue
            }else{
                child.setBackgroundColor(Color.TRANSPARENT);
            }
        }
    }
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-25 20:10:53

ListView的循环视图。这意味着,如果一个视图隐藏在一个组中,它将在新打开的组中使用。

一般来说,突出显示ListView中的选择不应该在ClickListener中实现,而应该在自定义Adapter中实现。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35636423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档