How to get child views of RecyclerView which are not visible - android

I am trying to get the views/view holder for the items of RecyclerView which are currently not visible in the list(I have scrolled down), like I scrolled to bottom and want the first child/item/row view.
I have tried using following methods but was unable to get the views/viewwHolder :
1. findViewHolderForLayoutPosition(position)
2. findViewHolderForAdapterPosition(position)
3. recyclerView.getChildAt(position)
4. recyclerView.getLayoutManager().getChildAt(position)
5. Inside adapter I made viewholder.setIsRecyclable(false) but still didn't work.
All of these approaches worked on some devices but not on all Android devices like Oppo devices.
I need some fool proof solution for this, please help with that.

Related

Android RecyclerView items empty when being swiped after switching apps

First of all, I have looked at similar questions (for example, this one: Android RecyclerView ItemTouchHelper revert swipe and restore view holder). This already helped a great deal, until I - more or less, accidentally - noticed my current (and hopefully, final) issue with this screen of mine.
Let's start with the setup:
I have a fragment with a RecyclerView filled with some CardView items (it's a little fancier, but that's what is important right now). I also created an ItemTouchHelper with the implementation of SimpleCallback (nothing in onMove()) to make swiping the items (right) possible. For the record: I am using API 27 right now.
So far, so good.
What I want to achieve:
I want to be able to swipe the items to be notified through the onSwiped() method of my SimpleCallback implementation. Also, I do NOT want the items to disappear, be removed, or otherwise taken out of my list of items in the RecyclerView. I just want to swipe them and have them return to their original position afterward (and yes, I know that it is sort of assumed that swiped items get removed). I am using the notifyItemChanged() method of my adapter in the onSwiped() method (also tried using notifyDataSetChanged()).
The problem:
Funnily enough, that works (mostly thanks to the aforementioned question) - until I hit that "app switch" button (don't know if there's actually one official name for it) and send the app to the background. Once I put it in the foreground again and start swiping, the items will not (visually) return. They are still on the list, and if I scroll or click the "app switch" button again, they will be displayed properly again (but won't return on swiping). Same if I navigate back one screen and come back to the list.
That makes me think something happens when I send the app to the background and recover it. Something different than navigating to that screen (in which case everything works as intended) - which I thought would more or less produce the same results. Any ideas what I might be overlooking here?
After some testing, I finally found the source of the issue:
I had both the RecyclerView and its Adapter initialised through onStart() of the Fragment and not onViewCreated(). After changing that, I got the proper results I wanted.
Lesson learned: Set your RecyclerView's Adapter as early as possible, unless you want to deal with sometimes strange issues.

How to handle dynamic view created in Recycler View

Actually, I am working on RecyclerView that shows some details along with images and all data comes from a database.
In my RecyclerView, I have used three diffs layout and each layout is used according to data coming from the database that means if only one image comes from database then one_image.xml layout comes to play, if two then two_imag.xml layout comes to play and if more than three then the third layout I am using.
My apps working fine for some extents but when i am trying to scroll down further, it get crashed. I come to know that the problem is on OnCreateViewHolder, meaning it doesn't get called when I go down further in Recycler View.
I searched alots on google but nothing work for me. Is it possible to call OnCreateViewHolder every time or some other way to solve this problem?
Thanks in advance
Sounds like the best option would be to use one layout file that has all three image views but just default them to visibility "gone" so they dont take up space. Then when you need to use them, set them to visibility "visible" when you are creating your viewholder.
Without seeing any actual code it hard to be more specific.

RecyclerView insert / remove animations

When you watch carefully, the insert animation in a RecyclerView works in 2 steps :
1) White space expands to make room for the new item
2) The item is animated in
Same thing for removal, reverse order
Examples :
https://github.com/wasabeef/recyclerview-animators
http://www.grokkingandroid.com/first-glance-androids-recyclerview/
The second step can be customized easily with the ItemAnimator class, but I cannot find any information on the first step. It happens to be very ugly with my layout (continuous color on the side).
LayoutAnimationController seems like a possible candidate to manage the first step, but adding a new one does not change anything, and following it with logs in setLayoutAnimationListener stays silent.
I cannot even disable this step, which would allow me to manage the animation manually in onBindViewHolder.
Actually sometimes the first step does not seem to fire, but I cannot explain why. I manage all the operations with notifyItem*, no notifyDataSetChanged.

How to stop scrolling listview above first Item?

My Query is in my ListView let say if I scroll to 1st position that is fine but now my ListView scrolls beyond that also like my fisrt item will also go down and there is no item before first item so blank screen comes which is looking very bad i hope, i have described well can anybody look into this.
I have seen this issue in Galaxy S while over other devices this behaviour is not followed. So I think some device manufacturers have modified their OS and we can't do anything in this case.

Android GridView Issue

In GridView the item at index 1 is not receiving click event but all other items are receiving click event in Galaxy S and in HTC Hero all items are receiving click event.What is this? Please explain.......thanks for giving time.
You shouldnt have any issues with this. i have used it tons of times. be sure to check the code you are using. Try to log the position in onItemClick see what it returns. also click don't work if you are using buttons or other similar controls inside the list rows. that requires a different aproach.

Categories

Resources