I've been having some trouble with onPause and onResume when implementing an ExpandableListView in my app. I may be doing this all wrong (in which case please tell me and I will endeavor to do it correctly) as I'm learning Android mainly from what I can find on the net. So, to jump into it, I've pretty much got my ExpandableListView working as I would like, but for one little bugbear. When I resume the activity (for example after the screen shuts off) I recreate my cursors (is that the best way to resume the activity? I was getting cursor errors before...) and then programatically expand the groups that were expanded when the activity was paused. Now ALL I want to do is change the background drawable for the expanded groups, but I can't seem to find a way to get their views. Any ideas?
@SuppressWarnings("unchecked")
@Override
protected void onResume() {
super.onResume();
String searchText = ((QueryString)this.getApplicationContext()).getQuery();
if((searchText == null || searchText.length() < 1))
if(!hasQuery)
refreshCursor();
else
searchCursor(queryString);
else
searchCursor(searchText);
ArrayList<Integer> ToExpand = (ArrayList<Integer>) ExpandedList.clone();
ExpandedList.clear();
for(Integer i : ToExpand)
{
listContent.expandGroup(i);
listContent.getChildAt(i).setBackground(getResources().getDrawable(R.drawable.listview_style_selected)); //NOT WORKING
}
}
EDIT:
What I really want is the View that I have just expanded programatically with listContent.expandGroup(i)
so that I can then change the background drawable manually. Unfortunately getGroupView
(where the background is normally changed) doesn't fire when you expand a group programatically so the background drawable remains unchanged. How can I get this view?