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

Native Development

Reply
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
Accepted Solution

Context dependent contextActions

Hi,

 

I was wondering how to realise context dependent contextActions. For example if I have a list of read and unread messages: how do I get the context menu to show the option "Mark as read" for the unread items and "Mark as unread" for the read items?

 

I hope this question is clear, if not please ask! Thanks for your advice.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: Context dependent contextActions

Use a different ListItemComponent for each type of message in your list - and then put the ContextAction inside the ListItemComponent, rather than the listview

 

i.e.

 

listItemComponents: [

 

   ListItemComponent {

      type: "unread_message"

      title: ListItemData.title

     

      contextActions: [
            ActionSet {
                ActionItem {
                    title: "Mark as Read"

               }

            }

      ]

  },

   ListItemComponent {

      type: "read_message"

      title: ListItemData.title 

 

      contextActions: [
            ActionSet {
                ActionItem {
                    title: "Mark as Unread"

               }

            }

      ]

 

 

  },

 

]

 

 

... and then in your datamodel, you need to make sure you identify each type of message appropriately, so the listview knows what kind of listitem to create. Use the itemType() callback in C++ or QML to accomplish this

 

 

Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Context dependent contextActions

Hi,

 

some corrections to your great idea:

 

  • A ListItemComponent has no property contextActions. However it can work like this:
listItemComponents: [
	    			        ListItemComponent {
	    			            type: "normal-read"
	    			            Container {
		                            layout: StackLayout {
		                                orientation: LayoutOrientation.TopToBottom
		                            }
		                            ImageView {
		    			            	objectName: "listItemComponent"
		    			                imageSource: ListItemData.imagePath
		    			                scalingMethod: ScalingMethod.AspectFit
		    			                horizontalAlignment: HorizontalAlignment.Center
		                            }
		                            Label {
		                                text: ListItemData.title
		                                horizontalAlignment: HorizontalAlignment.Center
		                                textStyle {
	                                        base: SystemDefaults.TextStyles.SmallText
	                                        color: Color.create(0.9, 0.9, 0.9)
	                                    }
		                            }	                        
            	    	            contextActions: [
            	    	                ActionSet {				                      
            	    	                    ActionItem {
            	    	                        objectName: "normal1OpenAction"
            	    	                        title: "Open"
            	    	                        imageSource: "asset:///images/openbook.png"
            	    	                    }
]}}]

 But now I have some troubles using findChild to get these ActionItems. I'll keep you guys posted.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550

Re: Context dependent contextActions

Hi Zezke,

 

Thanks for sharing the sample code.

 

I have a question related this sample code bellow:

 

contextActions: [
    ActionSet {				                      
         ActionItem {
            objectName: "normal1OpenAction"
            title: "Open"
            imageSource: "asset:///images/openbook.png"
         }
    }
]

At this point I need to call a C++ method after click on ActionItem "Open".

How can i achieve it.

 

I tried as bellow but C++ class object "_app" is not

 contextActions: [
    ActionSet {
       title: "Open Favorite"
           ActionItem {
               title: "Open"
               onTriggered: {
                  _app.loadHelpPage(root.ListItem.indexPath);
               }
          }
      }
 ]

 i am getting bellow error :

ReferenceError: Can't find variable: _app

 

Any help would be appreciated.

 

 

Thanks,

Shwarup Biswas
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550

Re: Context dependent contextActions

Hi Guys,

There is a reference i found in the thread helped me to fix the issue.

http://supportforums.blackberry.com/t5/Cascades-Development/ContextActions-inside-ListItem-can-not-a...
Thanks,

Shwarup Biswas
BlackBerry Development Advisor
tolang
Posts: 47
Registered: ‎04-19-2013
My Device: I love them all!

Re: Context dependent contextActions

Have you registered your "_app" variable with your context?
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Context dependent contextActions

Sorry for my late response, but this issue was fixed already by executing what tolang just suggested.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!