如何在子项单击ExpandableListView后更改父文本颜色?

时间:2018-01-23 18:48:12

标签: android kotlin

我已经使用onChildClickListener来处理子点击,但不知道如何更改父文本颜色:

val clickListener = ExpandableListView.OnChildClickListener{
       listView: ExpandableListView?, v: View?
       , groupPosition: Int, _: Int, _: Long
       ->
       listView?.collapseGroup(groupPosition)
       true
}
expandable_list_view.setOnChildClickListener(clickListener)

1 个答案:

答案 0 :(得分:1)

I think the best way would be to Create a list of parents that need colors changed and update them in get parent view, just like nosugar said

Set<Integer> coloredParents = new HashSet<Integer>();
val clickListener = ExpandableListView.OnChildClickListener{
       listView: ExpandableListView?, v: View?
       , groupPosition: Int, _: Int, _: Long
       ->
       listView?.collapseGroup(groupPosition)
       if(coloredParents.contains(groupPosition))
       {
          coloredParents.remove(groupPosition);
       }
       else
       {
           coloredParents.put(groupPosition);
       }


       true
}
expandable_list_view.setOnChildClickListener(clickListener)

//then in groupview

View getGroupView(int groupPosition)
{
   if(coloredParents.contains(groupPosition))
   {
      //set color here
   }
 }