1

I am using evant/binding-collection-adapter to render the list of items. I want to scroll to a specific position when after rendering the list. Following is my code, but it's not working. any help..??

XML.

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewFriends"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical"
                android:nestedScrollingEnabled="true"
                android:visibility="@{viewModel.isProgressBarVisible ? View.GONE : View.VISIBLE}"
                app:itemBinding="@{viewModel.singleItemFriendsList}"
                app:items="@{viewModel.friendDataItems}" />

activity:

   @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        invokeTheService();

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        getBinding().recyclerViewFriends.setLayoutManager(linearLayoutManager);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                getBinding().recyclerViewFriends.scrollToPosition(getViewModel().getFriendDataItems().size()-1);
            }
        }, 1000);

    }

ViewModel:

  public final OnItemBind<FriendItemViewModel> singleItemFriendsList = new OnItemBind<FriendItemViewModel>() {
        @Override
        public void onItemBind(ItemBinding itemBinding, int position, FriendItemViewModel item) {
            if (position == getSelectedTabListSize() - 1 && isLoadingAdded())
                itemBinding.set(BR.itemViewModel, R.layout.item_progress_friends);
            else
                itemBinding.set(BR.itemViewModel, R.layout.friends_listing_row);

            item.setItemPosition(position);
        }

    };

The library which I am using for RecyclerView: https://github.com/evant/binding-collection-adapter

mohammadreza khalifeh
  • 1,510
  • 2
  • 18
  • 32
Mudasir Sharif
  • 733
  • 2
  • 15
  • 31

1 Answers1

0

Put your Recyclerview in nestedScroll. Then set your recyclerview setNestedScrollEnabled(true). I think this will help you :)