Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
New Contributor
cfkane
Posts: 9
Registered: ‎02-17-2013
My Device: PlayBook
My Carrier: base
Accepted Solution

removing an item from a list fails

Hello,

 

I'm new to AIR und QNX and try to working through RIM's documentation.

Now I'm at http://developer.blackberry.com/air/documentation/playbook/ww_air_developing/Create_a_list_ms_197099...

 

The program creates a list. If I click a button it should remove an item from the list. But it doesn't. Maybe anybody has an idea why?

 

Just a second question:

Is there a difference at all between this two lines? Which variant is to prefer?

myList.removeItemAt(1);

myList.dataProvider.removeItemAt(1);

 

 

 

 

Here the important code parts:

 

import qnx.fuse.ui.listClasses.List;

 

private function initializeUI():void

{

  arrMonth.push({label: "Jan"});

  arrMonth.push({label: "Feb"});

  ...

  myList.dataProvider = new DataProvider(arrMonth);

}

 

private function myButtonEvent(event:MouseEvent):void

{

  //now remove an item

  //variante 1: works well!

  myList.removeItemAt(1);

 

  //HERE THE ERROR OCCURS

  //variante 2: doesn't work

  //error message: Could not find the item to remove

  myList.removeItem({label: "Jan"});

  //I'm still not understanding the label thing. So I tried this but it didn't work either

  myList.removeItem("Jan");

}

 

 

Thanks a lot,

Sebastian

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: removing an item from a list fails

You just need to call removeItemAt( index ).
Please use plain text.
New Contributor
cfkane
Posts: 9
Registered: ‎02-17-2013
My Device: PlayBook
My Carrier: base

Re: removing an item from a list fails

Yes, the call removeItemAt works.

But I would like to understand how removeItem works  - it's described in the documentation :-). So it should work

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: removing an item from a list fails

For removeItem, you have to give it the actual object that was originally added to the data provider (pointer reference). You cannot give it a new object that has the same values of the original object. If you dont have that, then you need to create a function that loops over your data provider array and compare the unique field (typically 'data') of the object being passed in, then call removeItemAt, based on the index of the array.

It is also a good idea not to rely on the label to be unique in the list. AS3 convention typically will have a 'data' field that is unique for the list. The data field can then be keyed on. Without it, and you have multiple items with the same label, will cause selection issues.
Please use plain text.
New Contributor
cfkane
Posts: 9
Registered: ‎02-17-2013
My Device: PlayBook
My Carrier: base

Re: removing an item from a list fails

Thank you very much, the picture is becoming clearer and brighter now :-)

 

SB

Please use plain text.