Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WearableRecyclerView .scrollToPosition not working for wear?

I have a set of items which should be populated in the list, for that I have used WearableRecyclerView. In some cases I want particular items to be in focus for selection. I am using scrollToPosition() method of WearableLinearLayoutManager but watch list do not scroll to the desired position, But the same thing on a mobile phone using RecyclerView and scrollToPosition() of LinearLayoutManager which is set to the RecyclerView working and scrolling to the desired position.

My code for wear watch:

WearableRecyclerView slots_rv = findViewById(R.id.slots_rv);
.....


WearableLinearLayoutManager wearableLinearLayoutManager =
    new WearableLinearLayoutManager(this, customScrollingLayoutCallback);
slots_rv.setLayoutManager(
    wearableLinearLayoutManager);

slots_rv.setCircularScrollingGestureEnabled(true);
wearableLinearLayoutManager.scrollToPosition(slotsAdapter.getPositionToFocus());
slots_rv.scrollToPosition(slotsAdapter.getPositionToFocus());
slots_rv.getLayoutManager().scrollToPosition(slotsAdapter.getPositionToFocus());
slots_rv.setAdapter(slotsAdapter);

What may go wrong here?

like image 704
Prashant Avatar asked Aug 28 '18 09:08

Prashant


1 Answers

Looks like you're not using the WearableLinearLayoutManager you declared in the 2nd line. You're setting the LayoutManager to a new instance so calling scrollToPosition won't work. Try the following

    WearableLinearLayoutManager wearableLinearLayoutManager = new WearableLinearLayoutManager(this, customScrollingLayoutCallback);
    slots_rv.setLayoutManager(wearableLinearLayoutManager);

    slots_rv.setCircularScrollingGestureEnabled(true);

    wearableLinearLayoutManager.scrollToPosition(slotsAdapter.getPositionToFocus());
    slots_rv.setAdapter(slotsAdapter);
like image 138
user1838169 Avatar answered Oct 17 '22 02:10

user1838169