DEVANDRIN KUNI
DEVANDRIN KUNI

Reputation: 81

SwipeToRefreshview swipe error

I have a swipe to refresh view and a listview within in the swipe to refresh view

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    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:id="@+id/refreshView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/txtEmpty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No data available"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="0dp"
            android:textSize="20sp"
            android:visibility="gone"
            android:layout_marginRight="0dp"
            android:layout_marginTop="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent">

        </TextView>

        <ListView
            android:id="@+id/ArrayList"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginTop="0dp"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginRight="0dp"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginLeft="0dp"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginBottom="0dp"
            app:layout_constraintBottom_toBottomOf="parent">

        </ListView>
    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>

I can scroll down the list but when i want to go back up, the swipe to refresh kicks in and I got to be able to view the entire list, any recommendations ??

and this is the implementation for the listener

srl = (SwipeRefreshLayout) view.findViewById(R.id.refreshView);
    srl.setOnRefreshListener(srfListener());

function for listener

protected SwipeRefreshLayout.OnRefreshListener srfListener() {
    return new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            update();
        }
    };
}

and update function

@Override
protected void update() {
    HomeActivity.getInstance().onResume();
    srl.setRefreshing(false);
}

Upvotes: 1

Views: 51

Answers (3)

komal akhani
komal akhani

Reputation: 573

Try this:

srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
            {
                @Override
                public void onRefresh()
                {
                  update(); 
                }
            });

instead of this:

protected SwipeRefreshLayout.OnRefreshListener srfListener() {
    return new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            update();
        }
    };
}

Xml:

Take Linear layout instead of ConstraintLayout.

Upvotes: 0

Vishal Vaishnav
Vishal Vaishnav

Reputation: 3422

Use like this

 <android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<ListView
    android:id="@+id/ArrayList"
    android:scrollbars="vertical"
    android:paddingBottom="85dp"
    android:clipToPadding="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</android.support.v4.widget.SwipeRefreshLayout>

Upvotes: 1

Sai Jayant
Sai Jayant

Reputation: 376

    <android.support.v4.widget.SwipeRefreshLayout
        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:id="@+id/refreshView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ListView
            android:id="@+id/ArrayList"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginTop="0dp"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginRight="0dp"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginLeft="0dp"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginBottom="0dp"
            app:layout_constraintBottom_toBottomOf="parent">

        </ListView>
</android.support.v4.widget.SwipeRefreshLayout>

Swipe refresh view should only wrap around the listview/recyclerViews .....not around the parent view

Upvotes: 0

Related Questions