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
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 .
call setTheme in onCreate() instead, or. redo setContentView (R. layout. mainscreen); to force reinstantiate all the layout.
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With