I found that I could grab a copy of my fragment names from my header resource when it was loaded:
public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.headers,target); fragments.clear(); for (Header header : target) { fragments.add(header.fragment); } } ... @Override protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } }
That way, I need to remember to update the list of fragments encoded in the code if I want to update them.
I was hoping to use getHeaders() and the existing list of headers directly, but it seems that the action is destroyed after onBuildHeaders() and recreated before calling isValidFragment() .
Perhaps this is due to the fact that the Nexus 7 I'm testing on does not actually perform actions with two panels. Hence the need for a static list item.
lane Jan 21 '15 at 13:43 2015-01-21 13:43
source share