Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView with LinearLayoutManager with header view that doesn't recycle

I want a ListView style RecyclerView with a header on top, AND I don't want the header view to get recycled, EVER.

I'm totally new to RecyclerView and LinearLayoutManager but I think what I want shouldn't be too difficult by extending LinearLayoutManager.

Additional info in case needed, but I think the above is enough:

I already have a RecyclerView with a header view at position 0. That part was easy enough with help from SO answers. But the view gets recycled, which is causing lots of issues with the EditText views in the header (trying to keep focus, restore focus, keep the caret visible, not do weird things with auto-correct feature, keep typing while EditText is technically gone/recycled, etc). So the simple solution would be to not have that view recycled, which I think is possible with a custom layout manager, but I have no idea where to begin.

I can't simply place the header view above my list, because I want it to scroll with the list (it's too tall to be fixed at the top of screen all the time).

like image 841
eselk Avatar asked Jun 02 '15 22:06

eselk


1 Answers

LayoutManager has LayoutManager#ignoreView(View) interface which according to documentation,

Flags a view so that it will not be scrapped or recycled.

Looks like what you need here

EDIT Google devs commented (here) that this flag is serving some other purpose, so it is not gonna solve "RecyclerView Header" problem. However, they are working on solution, so hold on tight and stay tuned

like image 182
Pavel Dudka Avatar answered Nov 04 '22 19:11

Pavel Dudka