Android Recyclerview update calendar on scroll

Viewed 869

I have a recyclerview with a calendar above. How is it possible to update the current date in the calendar if I scroll the recyclerview through the events of the day.

1 Answers

Yes, RecyclerVew provide an addOnScrollListener method

private OnScrollLoadMore mOnScrollLoadMore;//initalize in your activity class recycler_view.addOnScrollListener(mOnScrollLoadMore);// add onScrollListener to recyclerview

public class OnScrollLoadMore extends RecyclerView.OnScrollListener {

private IOnScrollListener mOnScrollListener;
private LinearLayoutManager mLayoutManager;
private Activity mContext;
private boolean mLoading = true;

public interface IOnScrollListener {
    void onScrollComplete();
}

public OnScrollLoadMore(Activity activity, LinearLayoutManager layoutManager) {
    this.mContext = activity;
    this.mLayoutManager = layoutManager;
}

public void setOnScrollListener(IOnScrollListener onScrollListener) {
    this.mOnScrollListener = onScrollListener;
}

public void setLoading(boolean loading) {
    this.mLoading = loading;
}

@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    Utils.hide_keyboard(mContext);
}

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
                 setLoading(false);
                mOnScrollListener.onScrollComplete();
}

}

//In Activity you want the event to triggered override public void onScrollComplete() { // do your work }

Perform your task of updating current date

Related