Tips for small student experience
If your UI is a GridView ListView control, you need to use the adapter to add data.
So sometimes the data in the List changes <> If the content changes, it is necessary to update the data.
Update the adapter data
Ada. notifyDataSetInvalidated ();
Ada. notifyDataSetChanged ();
The previous post by a senior is a good metaphor
We can use the granary to explain the difference between the two.
NotifyDataSetChanged: if there is less or more grain in the granary, a notification is sent.
NotifyDataSetInvalidated: the granary is changed. For example, the grain obtained from Warehouse A is now changed to the granary B.
In different cases, you can call unused functions for updates.
---------------------- Gorgeous split line ------------------------------------
However, in my tests, I found that I was In the first situation, but only changed the data content and did not change the address. No New data source was available, call yydatasetchanged () to solve the problem.
However, when I need to delete one of the items, subtract NUM by one, and call notifyDataSetChanged (), the first Item or the first few items are lost!
Click an Item and the icon returns to the normal number.
Finally, multiple tests showed that at the beginning, my items were 10 items. If you add or delete one Item to control the number of items to be greater than or equal to 10 items and call yydatasetchanged (), no problem will occur.
When you add or delete two items and the number of items becomes 9, the number of items is less than the number of items you set adapter () at the beginning.
I only found this rule, but I don't know the principle. If a great God knows it, please leave your answer. We also hope to help the children's shoes on the cards.