如何取消选中的所有其他子视图?我只想在任何时候保持一个突出的孩子。在下面的代码中,我能够高亮显示子元素,但是我在该组中选择的任何其他子元素都会被高亮显示。另外,如果我选择一个子组和切换组,那么位于相同位置的下一个组子也将被高亮显示。
//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);
}
}
}
});发布于 2016-02-25 20:10:53
ListView的循环视图。这意味着,如果一个视图隐藏在一个组中,它将在新打开的组中使用。
一般来说,突出显示ListView中的选择不应该在ClickListener中实现,而应该在自定义Adapter中实现。
https://stackoverflow.com/questions/35636423
复制相似问题