Introduction to key points of listview and adapter in Android Development
design sketch:
You can see that as soon as you open the activity, you will see 10 items
Let's look at the log information:
It can be seen that each convertview is null, and a new view is created to display it.
When we slide down, as shown in the figure below,
Since both item0 and item10 are displayed in half, item10 is also newly created. However, when item11 is to be displayed, Item1 reuses the instance of item0 because item0 is no longer on the screen. You can see from the following log information:
By analyzing the log information, we can see that the object of item11 is item0, the object of item12 is Item1, and so on.
In this way, by reusing convertview, you can avoid creating a new view every time, save memory and optimize the sliding effect of listview.
It can be seen that the getview call recovery of listview after modification is consistent with the behavior of recycler.
Why use wrap_ Content will be called repeatedly, which I haven't studied yet. However, I think it's because when Android depicts the listview, it doesn't know the height, so it uses an item to test the maximum height of the listview on the screen. I hope some friends who know can tell me. Thank you first!
Finally, if there is anything wrong above, I hope to point out that we can make progress with each other.
Supplement:
When using listview next, I found a very strange phenomenon. After notifydatasetchanged() is called, when listview gets getview() again, the order of all convertviews is reversed. Please see the screenshot below:
This should be caused by the fact that recyclebin is a stack structure.
other:
1. Disable divider:
android:divider="#00000000" android:dividerHeight="0dp"
2. Disable ListView selector:
convertView.setOnClickListener(null); If you just want to remove the color, you can use Android: listselector = "#00000000"
3. Disable header divider:
Android: headerdividerenabled = "false" 4. Getitemviewtype (int) and getitemviewtype (int)
Getitemviewtype (int) can not return int value larger than getviewtypecount(). Otherwise you will get java.lang.arrayindexoutofboundsexception at android.widget.abslistview $recyclebin.addscrapview (abslistview. Java: 3523) listview will return convertview of corresponding type according to different ViewTypes
General writing: