Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recycler view scroll to specific position

I have custom recyclerview with view Holder. I have one searchview. I want to move recycler view position as per searchview searched text. How can I achieve this task? so that search text filter will perform and according to filteration I will get position of filtered text. and using that I can move my focus (scroll) to that position.

Thank you

like image 604
Nik Avatar asked May 07 '17 08:05

Nik


People also ask

What is the difference between scroll view and recycler view?

In the practical on scrolling views, you use ScrollView to scroll a View or ViewGroup . ScrollView is easy to use, but it's not recommended for long, scrollable lists. RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists.

How scroll horizontal RecyclerView programmatically in Android?

For these methods to work, the LayoutManager of the RecyclerView needs to have implemented these methods, and LinearLayoutManager does implement these in a basic manner, so you should be good to go. @SoliTawako I guess scrollTo(int x, int y) you can also scroll view, but in a more fine-tuned way.


1 Answers

Try this:

myRecyclerview.scrollToPosition(position);

if not works in some cases(Keyboard opening etc.), try using delay.

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
         myRecyclerview.scrollToPosition(position);
    }
 }, 200);
like image 184
Oğuzhan Döngül Avatar answered Sep 19 '22 14:09

Oğuzhan Döngül