简体   繁体   中英

Sort recyclerview according to few keywords in java

I want to sort my recyclerview items like, when a particular keyword is searched, the matching named items should be on top and others items should be on bottom.

I'm working in android studio (Java).

you need to generate some numeric (sortable) score by which to sort your item list and maybe add it as a property of each item. Once the user types the search text you will calculate and update this value for each item. If you want to sort by string similarity I recommend the Levenstein distance . Read about it here with its java implementation. Then you need to implement thecomparable interface on your Item objects so you can sort them by that distance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM