0
如何取消选择所有其他选择的子视图?我试图在任何时间只保留一个孩子。在下面的代码中,我可以突出显示孩子,但我在该组中选择的其他孩子保持突出显示。另外,如果我选择一个孩子并切换组,则同一位置中的下一个组孩子也会突出显示。ExpandableListView - 如何只保持一个组孩子突出显示?
//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);
}
}
}
});
非常感谢您的支持,它指出我的方向正确,但您能否提供一个如何在自定义视图上工作的示例? – Dayan
https://github.com/F43nd1r/Multitool/blob/master/app/src/main/java/com/faendir/lightning_launcher/multitool/scriptmanager/ScriptListAdapter.java虽然这是多选也允许选择组,它应该显示原则。 (由我代码) – F43nd1r
好东西,谢谢! – Dayan