Android listview how to implement onscrollchanged and onscroll - android

I have a listview which will be populated more than 3000 items at a time. Each item has an imageview whose image I have to fetch from server. I want that when user scrolls and finish completes, listview load images of only those views which are visible on screen and also deletes images of those rows which has been scrolled up and down (not visible) on screen so that their images can be redownloaded when they get come on screen because I cannot keep images of all data due to memory limitations.

ListView already reuses views that are not visible, so no need to delete them afterwards, but you could optimize this by adding an scroll listener to the list and don't download images when the user is flinging, only when the scroll is stopping.

Related

Load all RecyclerView items at once

Default RecyclerView feature is to load only those items which are visible and load rest of the items as needed when user scrolls the list.
But my requirement is to load all items at once.
Any idea how to achieve this.
I am loading a Book and each page has multiple images for every line.
I am loading one image per item and I need to implement auto scroll feature for which I need to calculate whole recyclerview height.
I think instead of changing the default behavior of recyclerView if its possible use listView/gridView (until and unless you need StaggardGridView of recyclerView)
Just keep Recyclerview inside NestedScrollView. In simple first all the views regarding recyclerview items, that of cards is set to NestedScrollView and the things goes perfectly.

Android Recycler View: How to stop loading of images when recycler view is scrolling and start loading only when scroll is stopped?

How to stop loading of images when recycler view is scrolling and start loading only when scroll is stopped?
A common application feature is to load automatically more items as the user scrolls through the items (aka infinite scroll). This is done by triggering a request for more data once the user crosses a threshold of remaining items before they've hit the end.
The approaches for ListView, GridView and RecyclerView (the successor to ListView) are documented here. Both are similar in code except that the LayoutManager in the RecyclerView needs to be passed in to provide the necessary information to implement infinite scrolling.
Follow this link for more implementation details:
https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView
The question is slightly unclear, but I'm going to assume that you are talking about loading images into an imageview in recyclerview/listview items.
Answer:
Don't do it by hand. Use a library (like Glide) to load the images for you.

RecyclerView jump when item size changes

I have stumbled upon a problem regarding the RecyclerView. The situation is as follows:
I navigate from one Activity to another, the second one having a RecyclerView
The second activity reads an index out of the Intent and jumps its RecyclerView to that position (so it may "start" in the middle, from the user perspective)
The RecyclerView houses a list of news, each one having a network-obtained thumbnail
The thumbnails are obtained using Glide, with a placeholder (so a View inside a ViewHolder is at first inflated with height X, which may change after the thumbnail is obtained)
Now the problem is that when the user scrolls up from the item they started up, the ViewHolder is created and Glide makes a request for a thumbnail. It results in the list item having some height and changing it a second later, after the thumbnail is obtained, which in turn results in a nasty "jump" (because of the size change). It only happens 3-4 times, until enough ViewHolders get created to handle the whole RecyclerView.
Any idea how to prevent this? Ideally I would like to make the item above current to expand upwards.
I already tried making the items stack from the bottom, but it does not solve the issue, just makes it happen for the below items instead of the above ones. Also, I can not and don't want to predict the size of the obtained thumbnail.
I would use a place holder image in the Recycled View. And replace that image when it becomes available (downloaded).
This only works of course if you know the size of the tumbnails.

Scroll view flicker during view inflate

I have list of elements in scroll view. When clicking the element, I need to load data from server and inflate it in the clicked view. The data I fetch from server has variable heights. So I cannot fix the view height.
My problem is,
1- I click a view to fetch data.
2- I will be showing progressbar during server fetch.
3- I scroll down to view other data. In the mean time, if the the server fetch is success I will set the data. It will automatically adjust the scrollview. Since the scroll height is changed, the data I am viewing suddenly scrolls down.
I need to lock the scroll to the content I am viewing. I tried this solution, Stop ScrollView from setting focus on EditText but this is not working during scroll.
Pleas advice. Thanks in advance.

preventing ListView from reusing a ViewFlipper

I have a ListView and one of the rows (the first one) is a ViewFlipper.
Now, My problem is that when the ViewFlipper is scrolled out of the screen and back it gets reused. Usually it is a good thing to reuse only, but in my case when the ViewFlipper is recycled its starting from scratch.
I have 5 images in it and for example if the ViewFlipper was on the second image and you scrolled it out of the screen and back, its getting back to the first image. The timing and images are important since it is in sync with other components on screen and after reusing its out of sync.
So, How can I make the ViewFlipper continue running when its out of the screen so it will get back to the exact position and timing when its back on?
To prevent the recycling of the row containing the ViewFlipper(and because this row is the first one) you could simply set it as the header view for the ListView(but you'll need to set the header view before setting the adapter). Another approach would be to keep somewhere the current position in the ViewFlipper and when the row containing this ViewFlipper will be requested you would reset the ViewFlipper's position based on that saved position in the getView method.

Categories

Resources