Skip to content

Commit

Permalink
Add sample for SwipeRefreshLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
grantland committed Jan 28, 2016
1 parent ba48063 commit 7011460
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.database.DataSetObserver;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -32,8 +33,33 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

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

MyAdapter<ParseObject> adapter = new MyAdapter<>(createPager());
final MyAdapter<ParseObject> adapter = new MyAdapter<>(createPager());
listView.setAdapter(adapter);

final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
final ParseQueryPager<ParseObject> pager = createPager();
pager.loadNextPage(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
refreshLayout.setRefreshing(false);

if (objects == null && e == null) { // cancelled
return;
}

if (e != null) {
return;
}

adapter.swap(pager);
adapter.notifyDataSetChanged();
}
});
}
});
}

private ParseQueryPager<ParseObject> createPager() {
Expand Down
17 changes: 12 additions & 5 deletions ParseUI-Widget-Sample/src/main/res/layout/activity_list.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/list"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent">

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

0 comments on commit 7011460

Please sign in to comment.