Changing the position of an item in UIListView in the chain table

Source: Internet
Author: User

Changing the position of an item in UIListView in the chain table

Let's take a look at the mechanism of adding, inserting, and deleting UIListView, and then consider how to move a item in the linked list.

UIListView. h

 

/* Use an array to save all items */CCArray * _ items;

 

 

Void ListView: pushBackCustomItem (Widget * item) {/* add an item to the array */_ items-> addObject (item); remedyLayoutParameter (item); addChild (item ); _ refreshViewDirty = true;} void ListView: insertCustomItem (Widget * item, int index) {/* Insert an item to the array */_ items-> insertObject (item, index ); remedyLayoutParameter (item); addChild (item); _ refreshViewDirty = true;} void ListView: removeItem (int index) {Widget * item = getItem (I Ndex); if (! Item) {return;}/* remove an item from the array */_ items-> removeObject (item); removeChild (item); _ refreshViewDirty = true ;}

 

 

It can be seen that the management of all items in the linked list is only stored by arrays, so moving the position of an item is easy:

 

/* Declare a position movement function to move an item to a position in the linked list. Parameter 1: the current position of a item. Parameter 2: target Position */void changeItemOrder (int curIdx, int tarIdx) of an item );
Void ListView: changeItemOrder (int curIdx, int tarIdx) {if (curIdx = tarIdx) {return;} Widget * item = getItem (curIdx); if (! Item) {return;}/* re-adjust the position of the item: Remove and re-insert */_ items-> removeObject (item); _ items-> insertObject (item, tarIdx);/* adjust the layout and turn on the refresh switch */remedyLayoutParameter (item); _ refreshViewDirty = true; // sortAllChildren ();}

 

 

Usage:

 

ListView-> changeItemOrder (5, 0); // move the item with the index of 5 to the beginning of the linked list to become the first item


 

 




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.