Import Gradle support.v4
implementation 'com.android.support:support-v4:28.0.0'
Layout
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Cari"
android:id="@+id/btncari"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:textColor="#fff"
android:background="@drawable/bg_ui"
android:layout_height="wrap_content">
</Button>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/txtcari"
android:layout_toLeftOf="@+id/btncari">
</EditText>
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/btncari">
<ListView
android:layout_height="wrap_content"
android:layout_below="@+id/txtcari"
android:layout_width="wrap_content"
android:id="@android:id/list">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
Deklarasi di public ya untuk swipelayoutnya
SwipeRefreshLayout swLayout;
swLayout= (SwipeRefreshLayout) findViewById(R.id.refresh);
swLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
swLayout.setRefreshing(false);
new load().execute();//Load Data
}
}, 5000);
}
});
Selamat mencoba,
untuk load data bebas sesuikan data yang akan di muat.
EmoticonEmoticon