Last active
July 4, 2019 08:54
-
-
Save FarshidRoohi/562d76894c867f86b08f72703d684352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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