Skip to content

Instantly share code, notes, and snippets.

@FarshidRoohi
Last active July 4, 2019 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FarshidRoohi/562d76894c867f86b08f72703d684352 to your computer and use it in GitHub Desktop.
Save FarshidRoohi/562d76894c867f86b08f72703d684352 to your computer and use it in GitHub Desktop.
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
final MyAdapter adapter = new MyAdapter();
adapter.endLessScrolled(recyclerView);
adapter.addItems(getTempItems());
recyclerView.setAdapter(adapter);
// handled click item in recyclerView
adapter.setOnClickItemListener(recyclerView, new OnClickItemListener<String>() {
@Override
public void onClickItem(int position, String element) {
Toast.makeText(getApplicationContext(), "item click : " + element, Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClickItem(int position, String element) {
Toast.makeText(getApplicationContext(), "item long click : " + element, Toast.LENGTH_SHORT).show();
}
});
// handled endless recyclerView
adapter.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore() {
adapter.showLoading();
// request or load other items...
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
adapter.addItems(getTempItems());
}
}, 2500);
}
});
// get temp list item
public List<String> getTempItems() {
List<String> items = new ArrayList<>();
for (int i = 0; i <= 15; i++) {
items.add("item ");
}
return items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment