Update UIListView items, how?

Update UIListView items, how?
0.0 0


Anyone know the correct way to change the UIListView items after creation ?
My code is pretty much the same as the one in UIListViewTest in the cocos2dx v2.2.0 samples.

What I do when I need to change the items text in the list is:

  • Create a new CCArray with the new items string.
  • Call UIListView::initChildWithDataLength( size ) with the new size of the array.
  • Reset the index used in LISTVIEW_EVENT_INIT_CHILD event (m_nCount in the samples).

It works perfect.
But after some item refreshing, I get wrong behaviour. Basically, the top item in the list displays wrong text. I have to manually scroll down and then up again, and the display is correct again.
I’ve done some debugging inside my code and UIListView source, but found no evident mistake, that’s why I wonder if I’m not doing things right. How is UIListView supposed to be updated when some item text changes, for example?



UIListView listView = UIListView::create;
layout = Layout::create();

listView~~>addEventListenter(this, listvieweventselector(ShopScene::listViewEvent));
ulShop~~>addWidget(listView); @

here is some codes for reference.(i copy them to here, no comfirmation)

  1. layout~~>setPosition); should write as layout~~>setPosition(ccp(0,(5-i)*188));
    first item should at top of the screen.
  2. for (int i = 0; i < 5; ++i) ; 5 only show that it will create 5 item at initial, but other 183( 188 - 5 )items will create later. it will invoke event callback function.
  3. make sure addEventListenter is wrote before initChildWithDataLength.


@Ardhan S
same boat here, I’m trying to implement a chat window.
Looks like the UIScrollView only update the cells that is going to be shown (i.e. when the users scrolls the window).
So changing the data will not refresh the current view cell immediately.

I’m trying to add some code into UIListview to make it work the way I want :confused:


What I ended up doing is just recreate everything, except the UIListView object. This means releasing and creating all children again, and the strings array, and finally calling initChildWithDataLength().

In other words, to refresh the list content I do the exact same steps done to first create the list, excluding the UIListView creation (this could also be done, but I found that it was not required, and is good to avoid some unnecesary memory allocation).