Skip to content

Instantly share code, notes, and snippets.

@khaledkhj
Forked from VladSumtsov/MyActivity.java
Created August 4, 2018 17:15
Show Gist options
  • Save khaledkhj/f355d86c21e62de8a0afaf15bfde6f20 to your computer and use it in GitHub Desktop.
Save khaledkhj/f355d86c21e62de8a0afaf15bfde6f20 to your computer and use it in GitHub Desktop.
RecycleView PullToRefresh SwipeRefreshLayout
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_layout">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view" />
</android.support.v4.widget.SwipeRefreshLayout>
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.togethernetworks.basesdk.BaseActivity;
import com.togethernetworks.gallery.samples.mortar.UiModule;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MyActivity extends BaseActivity {
private RecyclerView recyclerView;
private SwipeRefreshLayout refreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
refreshLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
}
});
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
final LinearLayoutManager layoutParams = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutParams);
SomeAdapter adapter = new SomeAdapter(this);
recyclerView.setAdapter(adapter);
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(int newState) {
}
@Override
public void onScrolled(int dx, int dy) {
refreshLayout.setEnabled(layoutParams.findFirstCompletelyVisibleItemPosition() == 0);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment