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
New Contributor
F4bio
Posts: 4
Registered: ‎01-06-2013
My Device: Playbook, Dev Alpha A
My Carrier: drei.at

Problems with context menu

I have a problem with my contextmenu it seems like it can't access the contextproperty to call c++ functions or the indexPath of the selected List item

import bb.cascades 1.0
import com.remoteimage 1.0
import "global.js" as Global

Container {
    layout: DockLayout {
    }
    ListView {
        id: feedList
        objectName: "feedList"
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
        layout: GridListLayout {
            headerMode: ListHeaderMode.Standard
            columnCount: 3
        }
        dataModel: XmlDataModel {
            source: "feed.xml"
        }
        listItemComponents: [
            ListItemComponent {
                type: "header"
                Header {
                    topMargin: 8
                    title: ListItemData.title
                }
            },
            ListItemComponent {
                type: "feed"
                content: Container {
                    layout: DockLayout {
                    }
                    Container {
                        layout: StackLayout {
                        }
                        verticalAlignment: VerticalAlignment.Center
                        horizontalAlignment: HorizontalAlignment.Center
                        Container {
                            layout: DockLayout {
                            }
                            RemoteImageView {
                                url: Global.server_url + ListItemData.image
                                maxWidth: 250.0
                                maxHeight: 250.0
                            }
                        }
                        Container {
                            layout: DockLayout {
                            }
                            horizontalAlignment: HorizontalAlignment.Center
                            Label {
                                text: ListItemData.title
                                textStyle.textAlign: TextAlign.Center
                                horizontalAlignment: HorizontalAlignment.Center
                            }
                        }
                        contextActions: [
                            ActionSet {
                                actions: [
                                    ActionItem {
                                        title: "Delete"
                                        imageSource: "asset:///images/delete.png"
                                        onTriggered: {
                                            var selectedItem = feedList.dataModel.data(indexPath);
                                            _n3ws.requestDelete(selectedItem.id, selectedItem.custom);
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            }
        ]
        onTriggered: {
            var selectedItem = dataModel.data(indexPath);
            _n3ws.requestRSS(selectedItem.feedlink);
            navPaneFeed.push(articlesPage);
        }
    }
    ActivityIndicator {
        objectName: "feedIndicator"
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
        preferredWidth: 200
        preferredHeight: 200
        onStopped: {
        }
    }
    onCreationCompleted: {
        controlDelegateArticles.delegateActive = true
    }
}

 Any help would be nice :smileyhappy:

Please use plain text.
Developer
Concession
Posts: 31
Registered: ‎03-06-2011
My Device: Not Specified

Re: Problems with context menu

[ Edited ]

I actually did something similar in my app.

 

I had my context menu attached directly to the ListView. It does not give you the index path automatically but you can obtain it by using the listviewid.selected () method

 

My code is similar to this:

 

                contextActions: [
                    ActionSet {
                        title: "Context Menu"
                        actions: [
                            DeleteActionItem {
                                onTriggered: {
                                    var indexPath = idOfTheListView.selected ();
                                    //do stuff with index path (I used it to delete that item)
                                }
                            }
                        ] //end actions
                    } //end action set
                ]} //end listview

 You can also use a DeleteActionItem to get the standard RIM delete icon. It also places the delete context item on the bottom of the context menu.

 

Let me know if that helps.

Please use plain text.