I'm having a problem using SlidingUpPanel (https://github.com/umano/AndroidSlidingUpPanel) and FragmentStatePagerAdapter.
I have 3 fragments in the pager: the first two with a sliding panel (one a fragment and one a hardcoded layout) and the third without it. When I had a pager with just two fragments the panel were working perfectly fine. Now that I've added a third they are not working anymore.
At first the fragment are created correctly, but when I swipe all the way to the third and then come back the panel get messed up. Basically the panel that used to be on the first fragment is now on the panel of the second one, the hardcoded layout of the second panel is now gone and the panel of the first fragment is empty.
The main content of all fragment is still correct and behaves as intended.
I've drawn a schema of the situation to explain better:
My code to select the fragment is:
public Fragment getItem(int i) {
Fragment fragment = null;
switch (i) {
case 0:
fragment = new MatchListFragment();
break;
case 1:
fragment = new StreamFragment();
break;
case 2:
fragment = new PendingMatches();
break;
default:
break;
}
return fragment;
}
Layout of first fragment (MatchListFragment):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
CONTENT
</RelativeLayout>
<FrameLayout
android:id="@+id/scrollable_panel"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Layout of second fragment (StreamFragment)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/log_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:divider="@drawable/material_divider"
android:dividerHeight="1dp"
android:visibility="visible" />
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scrollable_panel"
android:layout_width="match_parent"
android:layout_height="88dp"
android:background="@color/white"
android:gravity="center">
<ImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:background="@color/light_gray" />
<ImageView
android:layout_width="25dp"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:src="@drawable/green_pill" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/icon"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/profile_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_profile_icon"
app:undertext="New" />
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/talk_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_talk_icon"
app:undertext="Learning" />
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/conversation_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_conversation_icon"
app:undertext="Teaching" />
<com.coffeestrap.android.Widgets.IconAndText
android:id="@+id/all_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
app:resource="@drawable/ic_all_icon"
app:undertext="All" />
</LinearLayout>
</RelativeLayout>
I cant really understand how to solve this especially because on the second fragment (StreamFragment()) the sliding panel layout is hardcoded and I can't understand why it loads everything else correctly and the replace the panel with the one from the first fragment(MatchListFragment).
In the end I strongly believe it's an issue with the library I'm using and not one caused by me. I've opened an issue on their github page here