Could you not just give an id to the layout where you want the elements to be colored and then something like:
layout_with_child_views = (RelativeLayout)nameView.getRootView().findViewById(id)
If your method returns the correct view then you could of course also stick to that.
Then fetch all child elements and change the background color:
for (int i = 0; i < layout_with_child_views.getChildCount(); i++) {
View child = (View) layout_with_child_views
.getChildAt(i);
tintBackground(child);
}
private void tintBackground(View view) {
ColorDrawable[] color = { new ColorDrawable(Color.WHITE),
new ColorDrawable(Color.GREY) };
TransitionDrawable trans = new TransitionDrawable(color);
view.setBackgroundDrawable(trans);
trans.startTransition(500);
}
Edit: I have been searching abit and to me it seems like you should be able to use the available listeners of ExpandableListView, so that in your ExpandableListAdapter:
@Override
public void onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
// use the parent to set default color to all other entries
// v is the view within the expandable list/ListView that was clicked
for (int i = 0; i < v.getChildCount(); i++) {
View child = (View) v.getChildAt(i);
// do highlighting
}
}
I have not tried this myself and am currently unable to setup a test project. Just wanted to give you an alternative approach in case you have not tried something similar.