0

I am trying to apply SwipeRefrshLayout on my tabbed view.

This is layout file of tab fragment in which i want swipeRefreshLayout

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

            <ListView
                android:id="@+id/list"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:divider="@null" />

    </ScrollView>

This is layout file of of activity

<RelativeLayout 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" >
    <LinearLayout
        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.support.v7.widget.Toolbar
                android:id="@+id/action_bar"
                style="@style/Widget.MaterialSheetFab.ToolBar" />
            <com.astuetz.PagerSlidingTabStrip
                android:id="@+id/tabs"
                style="@style/Widget.MaterialSheetFab.TabLayout" />
        </android.support.design.widget.AppBarLayout>
        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swiperefresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_below="@+id/appbar"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
        </android.support.v4.widget.SwipeRefreshLayout>
    </LinearLayout>
</RelativeLayout>

Code in fragment file:

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {

}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    if (SuperAwesomeCardFragment.listAchievements.getChildAt(0) != null) {
        StudentInfoMainActivity.swipeRefreshLayout.setEnabled(listAchievements.getFirstVisiblePosition() == 0 && listAchievements.getChildAt(0).getTop() == 0);
    }

}

after applying the above layout and code sample shown in the sample codes by google, i was successfully able to implement the swiperefreshllayout. But there was a problem of not able to scroll down, as swipe was overriding it. As per the thread on stack overflow https://stackoverflow.com/a/35779571/4180170, i added the code that solved my problem. But it added one more problem. A scenario where the first row of the list is bigger in height then my screen size, then the list shows only the first element. Other elements are not shown on the screen. This happens only when first element in the row is bigger. If i add another one row with height less than or equal to screen size, then all elements are being shown properly.

Other point that i would like to highlight is that if i use similar code in activity (Instead of Tabs or Fragments) than it works perfectly as expected and the following problem is not encountered. This is some kind of weird.

Image 1

Image 2

I have added two images: Image1: In this image, the first element in the list view have height less than the screen height, so all the element in the listView are visible on scrolling up and down.

Image2: Here i have just deleted the first element of list view from image 1. so the photo seen is the first element now in the listview. In this case as seen in the image, the height of the element(Image+padding and all) is greater than the screen size (height). Now when i try to scroll down, scroll is going only till the image is seen full. On Scrolling down, i am not able to see any of the other rows in the listview.

Update: Getting following line in Logcat multiple times

10-30 08:56:02.851 19665-19665/com.malav.holistree E/SwipeRefreshLayout: Got ACTION_MOVE event but don't have an active pointer id.
Community
  • 1
  • 1
Malav Shah
  • 472
  • 1
  • 6
  • 18
  • Can you post a screen shot and detail more your problem? I was not able to understand your problem properly. – jonathanrz Oct 29 '16 at 21:00
  • I have added screen shot and some more explanation related to screen shots – Malav Shah Oct 29 '16 at 21:32
  • 1
    Nice, now the question is more clear. Question: why you need a ListView inside a ScrollView? Also, I would suggest for you to change from ListView to RecyclerView, RecyclerView handles better with multiple scrolling views than ListView. – jonathanrz Oct 30 '16 at 21:05

1 Answers1

0

Posting answer as it can help someone else. Using ScrollView was actually creating problem. Used Linearlayout with RecyclerView as described by @jonathanrz. Works well..

Malav Shah
  • 472
  • 1
  • 6
  • 18