0

I have an aplication with a toolbar and an tab layout in appcompat v7. I navegate across the tabs with a View Pager, but the problem is where put an Expandable List View inside, doesn't scroll: this is my Java code from the principal activity

The minimal API is 15: Android Ice Cream Sandwicth 4.0.4

public class Principal extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_principal);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final TabLayout Tabulacion = (TabLayout) findViewById(R.id.Tabulacion);
    final ViewPager viewPager = (ViewPager) findViewById(R.id.Pager);
    final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), Tabulacion.getTabCount());

    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(Tabulacion));
    Tabulacion.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });
}

the Java code from the PagerAdapter

public class PagerAdapter extends FragmentStatePagerAdapter {
int intNumTabs;

public PagerAdapter(FragmentManager FM, int NumTabs) {
    super(FM);
    this.intNumTabs = NumTabs;
}

@Override
public Fragment getItem(int position) {

    switch (position) {
        case 0:
            TabHome Tab1 = new TabHome();
            return Tab1;
        case 1:
            TabLectura Tab2 = new TabLectura();
            return Tab2;
        default:
            return null;
    }
}

@Override
public int getCount() {
    return intNumTabs;
}
}

the XML code from the principal activity

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Principal">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    android:id="@+id/textView">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

    <android.support.design.widget.TabLayout
        android:id="@+id/Tabulacion"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.TabItem
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Inicio">
        </android.support.design.widget.TabItem>
        <android.support.design.widget.TabItem
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lectura">
        </android.support.design.widget.TabItem>
    </android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Pager"
        android:isScrollContainer="true"
        android:nestedScrollingEnabled="true"
        android:background="@color/backgroundColor" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

the XML code from the tab 2 fragment:

<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ListView">
</ExpandableListView>

The content of the Expandable List View is dynamic generated

2 Answers2

1

I solve it! I extract the view pager from the app coordinator layout in the XML, there is the final code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Principal">
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:id="@+id/textView">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/Tabulacion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.design.widget.TabItem
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Inicio">
            </android.support.design.widget.TabItem>
            <android.support.design.widget.TabItem
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Lectura">
            </android.support.design.widget.TabItem>
        </android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Pager"
    android:background="@color/backgroundColor" />
</LinearLayout>
0

Use a recyclerview instead of listview. I have implemented it in a view pager and it works perfectly. Recyclerview does virtually everything that a listview does and much more.

suku
  • 8,833
  • 13
  • 57
  • 108
  • In fact here is the same problem asked http://stackoverflow.com/questions/22729772/expandable-listview-inside-scrollview – suku Mar 27 '16 at 02:08