0

I have fragment in my app that acts as a portal to link to other fragments. The way I implemented this is by simulating a click on the nav drawer, which already handles all the code for switching fragments.

NavigationDrawerAdapter.ViewHolder v = (NavigationDrawerAdapter.ViewHolder) mDrawerList.findViewHolderForAdapterPosition(i);
v.itemView.performClick();

However, I get an error when I try to simulate a click on an item that isn't visible on the RecyclerView's current state. I know this is because RecyclerView only keeps visible views in its array of ViewHolders, but I need the ability to simulate a click on views that aren't in that array.

Yes, I know, I should just refactor my code so that I'm not doing janky things like simulating user clicks on the nav drawer. However, in the interest of time, and an understanding that this nav drawer will never really get incredibly big, as long as there are no other really negative caveats other than memory issues, I think it's the best working solution for the current state of my code.

user2968367
  • 43
  • 1
  • 4

1 Answers1

2

RecyclerView is intended to recycle Views. If you need to keep Views, use a ScrollView with a vertical LinearLayout.

You can probably scroll RecyclerView, wait for finishing and then simulate clicks. But anyway this whole thing seems wrong.

Have you considered NavigationView?

Community
  • 1
  • 1
Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99