I have 3 tabs in the FragmentStatePagerAdapter. I have a snippet for tab 1 that dynamically adds views to the 'linearlayout' container inside the relative layout. I dynamically add some views in a fragment of the 1st instance. I also added a full snippet in this linearLayout container with other up and down views. it works well .. everything is fine.
but when I go to the third page and come back. all views are there. but this full fragment disappeared ~~
EDIT
It disappears with tab1 and appears under the views in tab2, where another child fragment is added.
First of all, I have listFragment in tab1 and tab2. based on the listItem element, I load a snippet on each tab so that both snippets in tab1 and 2 inflate the same below xml and add dynamic views, but in some cases I add the full snippet instead of the view in the linear layout specified in xml.
The problem arose when I had to add two fragments in both newly added fragments on tabs 1 and tab2, after there were only lists and copied to tab3. upon return. the fragment in the "main fragment of tab1" disappeared and appeared below the fragment in the "main fragment of tab2"
this is a viewpager in which I change different fragments using the setItem method (fragment, position):
public static class ScreenSlidePagerAdapter extends
FragmentStatePagerAdapter {
public static ArrayList<Fragment> tabs_fragments = new ArrayList<Fragment>(
3);
public ScreenSlidePagerAdapter(FragmentManager fm,
ArrayList<Fragment> tabs) {
super(fm);
ScreenSlidePagerAdapter.tabs_fragments = tabs;
}
@Override
public Fragment getItem(int arg0) {
return tabs_fragments.get(arg0);
}
@Override
public int getCount() {
return tabs_fragments.size();
}
@Override
public int getItemPosition(Object object) {
if (tabs_fragments.contains(object)) {
return POSITION_UNCHANGED;
}
return POSITION_NONE;
}
public static void setItem(Fragment fr, int position) {
if (position <= 2 && position >= 0) {
tabs_fragments.remove(position);
tabs_fragments.add(position, fr);
} else
Log.d("adding tab", "wrong tab position to add fragment at");
}
}
linearlayout, 'll' - , tab1
ll.addView(getTitle("Set Message Receive Settings"));
Bundle b = new Bundle();
b.putInt("id", eventId);
b.putInt("event", eventTypeId);
Fragment fr = new FrEv_SMSReceive();
fr.setArguments(b);
getFragmentManager().beginTransaction()
.add(ll.getId(), fr, "fr_sms_receive").commit();
, "fr_event_container".
FragmentStatePagerAdapter
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EventDetails" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:padding="10dp"
android:textIsSelectable="false" />
<ScrollView
android:id="@+id/fr_event_container_scroll"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/sep1"
android:layout_alignParentLeft="true"
android:layout_below="@+id/title" >
<LinearLayout
android:id="@+id/fr_event_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<View
android:id="@+id/sep1"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_above="@+id/addOther"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:background="#000"
android:padding="10dp"
android:visibility="gone" />
<Button
android:id="@+id/next"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/addOther"
android:layout_alignBottom="@+id/addOther"
android:layout_alignParentRight="true"
android:layout_marginRight="54dp"
android:text="Next"
android:width="90dp" />