I'm trying to create a Fragment composed of multiple other fragments. First I have one fragment covering the entire layout, which you could swipe left or right to go the the other fragments using a PagerAdapter. Each of these Fragments will be composed of other fragments. At the moment it is composed of one textView, one Button and one Fragment (will be more repeats of this same fragment with small adjustments).
On each fullscreen-fragment I show which page I'm on by appending it to the TextView. This works.
I want to add the smaller Fragment dynamically. This doesn't work. It works on the first page that gets loaded, and it seems to be working when you go back to the previous page (only the exact previous) even when it didn't show the square when the page was first opened. This behaviour is demonstrated here:
You can see the text displays the fragment number. But the blue square should be on every one of the fragments. What could be wrong here?
CreateView() method of the fragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_level_selector, container, false);
Bundle bundle=getArguments();
levelNumber=bundle.getInt("levelNumber");
textView = (TextView) view.findViewById(R.id.text);
textView.append(" " + levelNumber.toString());
String[] colors = {"#0000ff", "#00ff00", "#ff0000", "#ffff00"};
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.include1, PictureFragment.newInstance(1, "#0000ff" ));
ft.commit();
return view;
}
Fragment layout xml
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<FrameLayout
android:id="@+id/include1"
android:transitionName="pic1"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:transitionName="pos1"
android:text="Hello, I am a Button"
android:onClick="sendMessage"/>
EDIT: this behaviour is only when setOffscreenPageLimit(0). If I set it higher only the first opened page has the blue square, all the others never have it. To me it seems like the getResources().getIdentifier() method always returns the object from the first page? Could this be true?