Any idea how to create a page indicator for recyclerview list ?
First you have to create another RecyclerView for the circles and put this code in the OnScrollListener of the first RecyclerView.
int[] firstVisibleItemPositions = new int[appList.size()];
int[] lastVisibleItemPositions = new int[appList.size()];
int position = ((StaggeredGridLayoutManager) listView.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItemPositions)[0];
View currentView = circlesList.getChildAt(position);
int lastPosition = ((StaggeredGridLayoutManager) listView.getLayoutManager()).findLastVisibleItemPositions(lastVisibleItemPositions)[0];
View lastView = circlesList.getChildAt(lastPosition);
ImageView circle;
if (dx>0) {
if (currentView != null && lastPosition != position) {
circle = (ImageView) currentView.findViewById(R.id.img);
circle.setImageResource(R.drawable.empty_circle);
}
if (lastView != null && lastPosition != position) {
circle = (ImageView) lastView.findViewById(R.id.img);
circle.setImageResource(R.drawable.selected_circle);
}
}else if (dx<0){
if (currentView != null && lastPosition != position) {
circle = (ImageView) currentView.findViewById(R.id.img);
circle.setImageResource(R.drawable.selected_circle);
}
if (lastView != null && lastPosition != position) {
circle = (ImageView) lastView.findViewById(R.id.img);
circle.setImageResource(R.drawable.empty_circle);
}
}