0

You suppose in simple recyclerview i have some text, i'm trying to find how can i search text in that and scroll to found text position, for example in simple recyclerview i have 10 row and on 4th position i have this text:

Hello World

i want to scroll to that on 4th position, how can i do that?

mahdi pishguy
  • 994
  • 1
  • 14
  • 43
  • On Arraylist of Adapter, whether that particular item is in the list or not, if its there, perform Cuatom search operation, on the arraylist index Item, if you found than take that position and programatically scroll recyclerview to that index – Lovekush Vishwakarma Feb 27 '17 at 17:46
  • @LovekushVishwakarma and what about if recylerview is big and text is middle of that? – mahdi pishguy Feb 28 '17 at 03:04
  • What about means? asking about focus or how to find sir? if your list is too big, than use exponential series to find your string. – Lovekush Vishwakarma Feb 28 '17 at 10:50

3 Answers3

1

Check your RecyclerView items for their texts, once you have a match to your desired text, get the item position and call:

myRecyclerview.scrollToPosition(position);
Ricardo
  • 9,136
  • 3
  • 29
  • 35
  • and what about if recylerview is big and text is middle of that? – mahdi pishguy Feb 27 '17 at 18:30
  • Thats something you need to test yourself to check either if it works as you want or not but you can also check this answer for http://stackoverflow.com/questions/26875061/scroll-recyclerview-to-show-selected-item-on-top – Ricardo Mar 01 '17 at 09:25
0

Iterate through your Adapter's data list and store the index for the item you're searching for. Then, use RecyclerView's scrollToPosition(y) method with that index to scroll to that particular item's position.

MarkInTheDark
  • 244
  • 2
  • 15
0

Workaround that I found on stackoverflow which really worked for me

myRecyclerView.scrollToPosition(position);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            myRecyclerView.smoothScrollToPosition(position);
        }
    }, 50); //sometime not working, need some delay

https://stackoverflow.com/a/57207024/6940711

Pravin Yadav
  • 337
  • 3
  • 12