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
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
}