The two pictures above show the favorite buttons (Pentagram) and thumbs up buttons (number of likes );
This is common during Project creation. First, explain my requirements:
For favorites: First, there are about 13 + pages with favorite button interactions throughout the project. If you calculate the tag, there will be no more options, that is to say, the number of pages is basically unknown. When you click this favorite button, the page will be lit up. When you click it again, the page will be restored. Click in the middle. After the operation is successful, the system will interactively update the status data of the favorites in the background on the server, so that you can maintain the status of favorites or not added to the favorites next time.
For likes, the number of likes is basically the same as that of favorites, but the number of likes is increased. The numbers of likes should be changed instantly as the click interaction occurs;
Then, the problem arises!
First, let's talk about the listView mechanism. If listView enters this page for the first time without allowing listView to load all the items you requested at a time, it loads the number of items of listView based on the number displayed on the mobile phone screen. After loading the first version (the item displayed on the mobile phone screen), you drag the listView to slide up to display the remaining items you requested. Each time the getView (); in the next adapter is displayed, it is called to set the data and view display of this item. Then, if you drag the listView down again to display the first few pieces of information of the listView, each of the hidden items displayed on the top is blocked, and getView () in the adapter (); it will be overwritten and loaded once to set the data and view display of the item;
Therefore, if you click the favorites or likes button in the normal way and set the ta status instantly. When you drag him out again after covering him, you are surprised to find that "why is the status identical when no operation is performed ?". Then, these operations must be performed locally. It is not possible to directly synchronize them to the background and then fill in the listView display by calling new data that has changed the stock status; this is because it consumes too much memory on the phone, and the page needs to be re-loaded for every interaction, re-requesting data, which brings a deep dislike to the user experience. It is estimated that your application will be uninstalled immediately! Then, if you remember your interaction status, it may work for a single page, but for dozens of such pages, how much redundant code do you need to repeat, you can estimate it as well. Too much trouble!
Then, I will share with you the idea that I have been able to perfectly solve this interaction situation for three days and continue to be able to synchronize with the background server:
For example, after you click the favorite button and submit the status to the background. A bug occurs when you slide the listView because the local status data has not changed. Then, your listView will load old data with outdated settings and display it on the item of the listView. Therefore, when loading the set data in listView, ensure the consistency between the local data and the background data in order to make the item display the correct content. The local data that contains this state generally includes: the object that contains this state or something, that is, the following: database tables, bean class objects of the class, bean class objects of the class adapted by the adapter, etc. Then, after you click "interaction" and submit your favorite status to the background, you need to immediately update all the local interaction states of the favorite. This means that your local data is always synchronized with the background data! Then, no matter how you slide your listView, ta will load and set the correct data for display !!
Display the interaction of favorites and likes on the ListView correctly.