is there any way to determine the type of a visibl...
# android
is there any way to determine the type of a visible item in RecyclerView by asking the adapter?
google 1
If i remeber correct, tou can ask layout manager smth like getLastVisibleItemPosition
And getFirstVisibleItemPosition
☝️ 1
You have to remember that the recycler view is just a ViewGroup holding views. It is called
view because even if you add 1000 items to it, it will not render 1000 items but only the visible ones. This is to make things a lot more performance friendly. So knowing that RecyclerView is basically a ViewGroup (Just like a LinearLayout/RelativeLayout/ConstraintLayout) that will tell you that once you get its children, it will return child views. Meaning, the one it actually renders, as it is not rendering and adding 1000 views if only 5 are visible. Inside you have an adapter to feed the data and a layout manager to position/load the views. So in that case, Recyclerview has a helper function:
Copy code
parent.getChildAdapterPosition(view) // parent is the recyclerview
With this position you can check for the item type
The views within the recyclerviews are just simple views, they don't know about viewtypes and stuff like that. There is magic within the adapter for that
That did the trick! Thanks a lot!