【发布时间】:2016-02-25 19:22:31
【问题描述】:
如何取消选择所有其他已选择的子视图?我试图在任何给定时间只突出显示一个孩子。在下面的代码中,我可以突出显示孩子,但我在该组中选择的任何其他孩子都保持突出显示。另外,如果我选择一个孩子并切换组,相同位置的下一组孩子也会被突出显示。
//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);
}
}
}
});
【问题讨论】:
标签: android expandablelistview expandablelistadapter