Cross-platform SDK and HTML5 tools for mobile app development
X
 
3 posts / 0 new
Last post
widagroup
widagroup's picture
Offline
Mobile Conjurer
Joined: 18 Feb 2012
Posts:
Clear ListView

Hi All,

I'm using NativeUI JS, and I'm just wondering... what is the best way to clear a list view of all its items?

I cant seem to find a way of getting the number of items in the list to do:
document.getNativeElementById("lvScreen").removeChild(index)

And the following do not work either:
mosync.nativeui.maWidgetDestroy("lvScreen");
document.getNativeElementById("lvScreen").clear();
document.getNativeElementById("lvScreen").clearlist();
document.getNativeElementById("lvScreen").clearitems();

lvScreen is the ID of the ListView.

Thanks for your help.

Ali Sarrafi
ali.s's picture
Offline
MoSync User
Joined: 20 Nov 2010
Posts:
The easiest way is to delete

The easiest way is to delete the listView and create it again, because then it actually deletes all of its children as well. Ovidius solution would work as well except that you have to use getNativeElementById. So this should work:

var parentElem = document.getElementById('listParent');
   
  parentElem.removeChild('lvlList');

But what you said can be good new feature for us to work on :), a clearChildren function maybe.

 

 

 

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:
The NativeUI ListView is a

The NativeUI ListView is a widget and kind of acts as a blackbox from DOMs perspective. To work with the widget itself you need to use the API for working with the ListView (the items that make the list are part of the widget not part of Document Object Model). Your code would work only if your list is a HTML list.

Possible solution:

i) Remove the HTML element that points to your list, e.g. lvlList (this ID is recognized by the DOm but not by the C++ part).

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }var parentElem = document.getElementById('listParent');
var myElem = document.getElementById('lvlList');
parentElem.removeChild(myElem);{/syntaxhighlighter}

ii) Add a new Native UI list as a DOM element having the same ID (in our ex: as a child of parentElem)

Not verified solution: using JavaScript get a hold of your NativeUI list and chage it's properties (through js messages). I'll ask around to see if this approch is supported by the API.

Login or register to post comments