Make the interaction of favorites and likes correctly displayed on the ListView, listview

Source: Internet
Author: User

Make the interaction of favorites and likes correctly displayed on the ListView, listview


















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 !!


In winform, how do I set a button, click to display a group of new data in listview, and then click listview to display the original data?

First, add a column with the value cyclically. Use the following method.
ListView1.Items. Add ("List item text", 0 );
Save the old data and then clear the listview
ListView1.Items. Clear ();
Use the Add method to Add new data.
You need to cyclically change the New and Old data, add a boolean type variable, and change it after each click.

Click the node of the treeview control to display all the data in the subnodes under the node to the listview.

Normally, you should retrieve the database again in the click event !~ Extract the data and place it in your ListView.

Or you can retrieve the data from the data source that you constructed the tree.

If you want to retrieve the value from the tree, first obtain the current node (TreeViewItem), then loop through TreeViewItem. Items, and retrieve the TreeViewItem in it!
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.