Skip to content

Commit c23eb79

Browse files
committed
Add sample for SwipeRefreshLayout
1 parent 01cfc30 commit c23eb79

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

ParseUI-Widget-Sample/src/main/java/com/parse/ui/widget/sample/ListActivity.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.database.DataSetObserver;
44
import android.os.Bundle;
55
import android.support.annotation.Nullable;
6+
import android.support.v4.widget.SwipeRefreshLayout;
67
import android.support.v7.app.AppCompatActivity;
78
import android.view.LayoutInflater;
89
import android.view.View;
@@ -32,8 +33,33 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3233

3334
ListView listView = (ListView) findViewById(R.id.list);
3435

35-
MyAdapter<ParseObject> adapter = new MyAdapter<>(createPager());
36+
final MyAdapter<ParseObject> adapter = new MyAdapter<>(createPager());
3637
listView.setAdapter(adapter);
38+
39+
final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
40+
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
41+
@Override
42+
public void onRefresh() {
43+
final ParseQueryPager<ParseObject> pager = createPager();
44+
pager.loadNextPage(new FindCallback<ParseObject>() {
45+
@Override
46+
public void done(List<ParseObject> objects, ParseException e) {
47+
refreshLayout.setRefreshing(false);
48+
49+
if (objects == null && e == null) { // cancelled
50+
return;
51+
}
52+
53+
if (e != null) {
54+
return;
55+
}
56+
57+
adapter.swap(pager);
58+
adapter.notifyDataSetChanged();
59+
}
60+
});
61+
}
62+
});
3763
}
3864

3965
private ParseQueryPager<ParseObject> createPager() {
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="match_parent"
4-
android:layout_height="match_parent">
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
55

6-
<ListView
7-
android:id="@+id/list"
6+
<android.support.v4.widget.SwipeRefreshLayout
7+
android:id="@+id/refresh"
88
android:layout_width="match_parent"
9-
android:layout_height="match_parent"/>
9+
android:layout_height="match_parent">
10+
11+
<ListView
12+
android:id="@+id/list"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent"/>
15+
16+
</android.support.v4.widget.SwipeRefreshLayout>
1017
</FrameLayout>

0 commit comments

Comments
 (0)