Cross-platform SDK and HTML5 tools for mobile app development
X
 

addTo, addChild problem

4 posts / 0 new
Last post
Fredrik Axtelius
frax's picture
Offline
Joined: 25 Jul 2012
Posts:
addTo, addChild problem

Hi!

Im trying to update a listview which I dynamiclly populate every now and then. Since I can't remove item by item I remove the whole list and add it again but this fails for some reason.

If I add the list using list.addTo('layout') it appreas just fine but can't later be located using getNativeElementById. If I user layout.addChild(list) I can later pickit up with getNativeElementById but for some reason when I user addChild the list isn't shown on the screen.

The following code shows the problem. Just create a standard NativeUI Reload demo project and replace the counterButtonClicked() with the following code.

{syntaxhighlighter brush: jscript;gutter: false; light: true; fontsize: 100; first-line: 1; }function counterButtonClicked()
{
// Remove listView
var listView = document.getNativeElementById('myList');
var listViewParent = document.getNativeElementById('mainLayout');
if (listView) {
mosync.rlog('found one');
listViewParent.removeChild('myList');
mosync.rlog('removed'); // never get's here if I use addTo
}

// Create new list
var lv = mosync.nativeui.create('ListView', 'myList', {
width: -1,
height: -1
});
mosync.rlog('created');

// using addTo really adds the list to the layout
// but fails on the second run when I try to remove it
lv.addTo('mainLayout');

// using addChild instead doesn't visually add the list
// to the layout (for some reason) but the code for
// finding and removing the list works
// listViewParent.addChild('myList');

/*
var lvi = mosync.nativeui.create('ListViewItem', 'lvi1', { text: new Date().getSeconds() });
lvi.addTo('myList');
*/
}{/syntaxhighlighter}

I've been trying things the whole weekend but just can't get it to work, help please :)
-Fredrik 

Fredrik Axtelius
frax's picture
Offline
Joined: 25 Jul 2012
Posts:
Anyone? It's on my last

Anyone? It's on my last screen before my app is finished, really need some help.

Fredrik Axtelius
frax's picture
Offline
Joined: 25 Jul 2012
Posts:
Removing the items was my

Removing the items was my first instinct but I never got it to work. Then I searched the forums and found this:
http://www.mosync.com/content/clear-listview

That's why I decided to kill and recreate the ListView. 

Iraklis Rossis
Iraklis Rossis's picture
Offline
Mobile Archmage
Joined: 3 Aug 2011
Posts:
Why cant you remove the list

Why cant you remove the list items themselves? Is there an error?

Login or register to post comments