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
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

BB10: Adding context menu to list

In case this is useful to someone.  Little bit of a pain to setup, but it works:

 

// build menu
var csmenu :Vector.<ActionBase> = new Vector.<ActionBase>();
csmenu.push( new Action( 'Edit'	, new edit_icon()	, {id:'edit'} ) );
csmenu.push( new Action( 'Map'	, new map_icon()	, {id:'map'} ) );
			
var t:ActionSet = new ActionSet( csmenu, 'Your Title Here', '', new DeleteAction( 'Delete', new trash_icon(), {id:'delete'} ) );

var sets :Vector.<ActionSet> = new Vector.<ActionSet>();
sets.push( t );

// set to list
this.poi_list.contextActions = sets;
this.poi_list.addEventListener( ActionEvent.ACTION_SELECTED, ActionSelected );

// ...

//////////////////////////////////////////////////////////////////////////////
private function ActionSelected( event : ActionEvent ) : void
{
  switch( event.action.data.id )
  {
	case 'edit'   : this.EditPoi(); break;
	case 'delete' : this.DeletePoi(); break;
	case 'map'    : this.gotoMap(); break;
  }
}

 

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: BB10: Adding context menu to list

To know which item is selected, use the list's selectedItem attribute. It is best to check if this is null before proceeding since it appears that in some cases, it get set to null during the context menu selection is shown.
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: BB10: Adding context menu to list

WTH: 5000th post!
Please use plain text.
Developer
Developer
mdd
Posts: 224
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: BB10: Adding context menu to list

Thanks, I did get it working too, though I did wonder why "contextActions" is a "Vector"?  When/How would any set other than the first be activated?

 

Regards,

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: BB10: Adding context menu to list

Vector force the type of object to be in it, where Array you can have anything. Though not important here, Vector's are faster to traverse then Array's and are good to use where yo uhave a large number of items in it. It's better programming, but the syntax is a little ugly (think C++ templates).
Please use plain text.
Developer
Developer
mdd
Posts: 224
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: BB10: Adding context menu to list

Vector vs Array not the question:

 

why more than 1 ActionSet?

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: BB10: Adding context menu to list

I have no idea. That is how the API is. I'll see if I can get clarification.
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: BB10: Adding context menu to list

The multiple ActionSets are there to mimic the Cascades API. It allows you to cycle thru the context menu (different state conditions). However, only the first one is ever used at this time. It is there for future design considerations.
Please use plain text.
Developer
Developer
mdd
Posts: 224
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: BB10: Adding context menu to list

understood - thanks for the clarification.

Please use plain text.
Developer
agaripian
Posts: 131
Registered: ‎12-02-2010
My Device: Z10 & Dev Alpha C
My Carrier: T

Re: BB10: Adding context menu to list

Thanks for this! But is it possible to add  a context menu to a Flex List instead? Have you been able to do this? Can I make the context menu appear without associating it to a list?

---------------------------------------------------------------------
Developer of Stocks for Blackberry 10
Please use plain text.