0

I'm creating an Android app using MVVM and view binding. My home fragment has a ScrollView with three horizontal RecyclerViews inside.

When the user navigates to another view by clicking on an item & then returns to the home fragment on back press, I want the ScrollView to be at the top instead of returning to the part of the screen that was clicked.

I've tried this in my home fragment, but it didn't so anything:

binding.container.requestFocus(View.FOCUS_UP);
binding.container.scrollTo(0,0);

Any other suggestions would be appreciated.

Iam Me
  • 33
  • 8
  • Does this answer your question? [Can I scroll a ScrollView programmatically in Android?](https://stackoverflow.com/questions/6438061/can-i-scroll-a-scrollview-programmatically-in-android) – Narendra_Nath Jul 27 '22 at 19:27

1 Answers1

0

This solved my problem:

binding.container.post(new Runnable() {
    @Override
    public void run() {
        binding.container.fullScroll(View.FOCUS_UP);
    }
});

Thank you @narendra-nath

Iam Me
  • 33
  • 8