3

Tengo un proyecto en el que agregue un Navigation Drawer y una ToolBar con ViewPager, con dos Tab.

Quiero que en la primera Tab aparezca un listado y que cuando se seleccione un ítem del listado aparezcan sus detalles al lado, en el otro fragmento, dentro de la misma Tab. Es decir, que en la tab1 aparezca un fragmento que sea el listado y a su derecha otro con los detalles.

He conseguido que aparezca el listado, sin embargo no soy capaz de insertar otro fragmento en esa misma Tab, para poder ver los detalles.

Código Main Activity:

PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
Toolbar();
drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav);
crearDrawer(navigationView);           
mViewPager = (ViewPager) findViewById(R.id.pag);
seleccionarUnItem(navigationView.getMenu().getItem(1));
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
tabLayout = new TabLayout(this);
tabLayout.setupWithViewPager(mViewPager);
for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if(i==0) {
                tab.setText(R.string.list);
            }else{
                tab.setText(R.string.geo);
            }
        }
appBarLayout.addView(tabLayout);

El ̣layout de la Main Activity:

<android.support.v4.widget.DrawerLayout   
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<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:orientation="vertical">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<Button
    android:id="@+id/popup"
    android:layout_width="1dp"
    android:layout_height="1dp"
    android:textSize="0dp"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

<RelativeLayout
    android:id="@+id/principal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" >
    <fragment
        class="es.DetailsFragment"
        android:id="@+id/details"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    </FrameLayout>
</RelativeLayout>
</LinearLayout>
<!-- Menú Deslizante -->
<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/cabecera_drawer"
    app:menu="@layout/menu_drawer" />
    </android.support.v4.widget.DrawerLayout>

Mi pregunta es:¿Cómo puedo insertar dos fragmentos en la misma tab?.

1 respuesta 1

1

Si deseas insertar otro fragmento simplemente insertalo dentro del FrameLayout

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" >
    <fragment
        class="es.DetailsFragment"
        android:id="@+id/details"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <fragment
        class="es.DetailsFragment2"
        android:id="@+id/details2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    </FrameLayout>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.