问题
I was wondering if there is any optimized way to create an adapter that holds more than 1k object in it. I have tried the following but still the results were not promising .
A.View holder pattern-It helped but when the object size increased it started have issues
B.Note: I could have used a paginated api which passes a defined number of objects but I annot have paginated Api in my scenerio.
C.My list do have images in it but I have taken care of that.Its not a problem now.
Let me know of any new ways to achieve a adapter that can have a large number of object list in it without any issues.
回答1:
As far as I know, I use some structure below
- Use ViewHolder
- Do not create new object if you not use
- Optimizing Layout Hierarchies
https://developer.android.com/training/improving-layouts/optimizing-layout.html
- Prevent Overdraw
https://developer.android.com/tools/performance/debug-gpu-overdraw/index.html
Load
ImageView
inListView
: I am using "Universal Image Loader" and enable mode: stop load image when scrollingOptimize code in the getView(...) function of
ListView
Adapter
: Try to make the code clear and short, restrictive useif{}else{}
If you have a problem with OutOfMemory, take a look at Java Reference https://www.rallydev.com/blog/engineering/java-references-strong-soft-weak-phantom
Try to use RecycleView, it much more powerful, flexible and a major enhancement over ListView https://stackoverflow.com/a/31199564/5381331
来源:https://stackoverflow.com/questions/33774215/optimized-list-view-with-1k-object-list