Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Pull down to refresh the whole page

I am making a feature that will let users to pull down a page anywhere in the application to check if they have a connection to the database server. I have followed this website, but it needs to Scrollview or ListView to function. All of my layouts are in a RelativeLayout only. Is there a way to do this without converting my whole layout to a ScrollView?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.infomaninc.appinlisv2.NewClaim">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:id="@+id/rlHeader" >
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#1BB52D"
    android:gravity="center"
    android:padding="3dp"
    android:id="@+id/rlFooter" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/footer_value"
        android:id="@+id/tvFooter"
        android:textColor="#fff"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/app_name"
        android:id="@+id/tvLoggedOn"
        android:textColor="#fff"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
</RelativeLayout>

Don't mind the contents of the code. It's just a snippet of a page. How will I implement the pull down to refresh if my page looks like this?

So far I have followed this tutorial:https://guides.codepath.com/android/Implementing-Pull-to-Refresh-Guide#step-2-setup-swiperefreshlayout

like image 925
OrdinaryProgrammer Avatar asked Sep 15 '15 08:09

OrdinaryProgrammer


People also ask

How do you swipe to refresh on Android?

To add the swipe to refresh widget to an existing app, add SwipeRefreshLayout as the parent of a single ListView or GridView . Remember that SwipeRefreshLayout only supports a single ListView or GridView child. You can also use the SwipeRefreshLayout widget with a ListFragment .

How do I force an entire layout view refresh?

call setTheme in onCreate() instead, or. redo setContentView (R. layout. mainscreen); to force reinstantiate all the layout.

What is pull down to refresh?

Pull-to-refresh is a touchscreen gesture that consists of touching the screen of a computing device with a finger or pressing a button on a pointing device, dragging the screen downward with the finger or pointing device, and then releasing it, as a signal to the application to refresh the contents of the screen.


1 Answers

You can also look for SwipeRefreshLayout. Although it needs a ScrollView/ListView as a child, but it wouldn't matter since all your data is being displayed in a single page. Just remember to set android:fillViewport="true" in your ScrollView and you'll do fine. You can go ahead as follows:

    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.your_id_for_swiperefreshlayout);
    swipeRefreshLayout.setOnRefreshListener(this);
    @Override
    public void onRefresh() {
        //reload the data
    }
like image 58
sri Avatar answered Sep 28 '22 14:09

sri