I am working on Android app which has 4 tabs in action bar (main_activity.xml).
In one tab, i would call it MapListFragment (map_list_fragment.xml), i have to show two different fragments (list and map view representation of some data). All other tabs are fragments and are put in the same container as MapListFragment (id/main_fragments_container).
So, map Fragment is shown first, and buttons map and list are shown in the bottom. Only one Fragment (map or list) is shown at the time, and on button click (map or list) you can show other Fragment, and go back to first Fragment again clicking on the button. Container for these map and list Fragment is (id/fragments_container). I change this Fragment by calling replace() method on FragmentTransaction and i forward same container (id/main_fragments_container) that ActionBar TabListener uses to change tabs. I also tried to create new container for particularly this tab and use him for all operations inside this tab, but I ran into same problems. Changing this Fragment works well, but...
Then I added button at the ActionBar which calls new Fragment that should represent view for adding some data. Container for this Fragment is (id/main_fragments_container) Problem is that, when i go back to MapListFragment, I cannot get same behavior as initial. First question would be is this best work practice or should i call Activity instead Fragment?
When I call new Fragment from ActionBar button, I always remove map fragment (I got same result and when i don't remove), and when I go back to MainFragment blank view is shown, although I call addToBackStack() method.
So I have multiple problems in here, and I hope that I explained some of them, can anybody know what can i try to get this working?
XML layout of MainActivity that contains 4 tabs.
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:background="@android:color/white">
<LinearLayout
android:id="@+id/main_fragments_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
MapListFragment layout which contains fragments and two buttons, fragments are added dynamically.
map_list_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/events_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white" >
<LinearLayout
android:id="@+id/fragments_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@android:color/white"
style="?android:attr/buttonBarButtonStyle"/>
<Button
android:id="@+id/button_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@android:color/white"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>