Another way to do this is to place tags on your snippets when you add them to the action.
For example, if you dynamically add 4 fragments, you can add them as:
for (int i = 0; i < NUM_FRAGMENTS; i++){ MyFragment fragment = new Fragment(i); fragmentTransaction.add(R.id.containerId, fragment, SOME_CUSTOM_PREFIX + i).commit() }
Then, if you need to get all the fragments later, you can do:
for (int i = 0; i < NUM_FRAGMENTS; i++) { String tag = SOME_CUSTOM_PREFIX + i; fragmentList.add((MyFragment) fragmentManager.findFragmentByTag(tag)); }
theelfismike Feb 04 '13 at 16:43 2013-02-04 16:43
source share