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
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus
Accepted Solution

ListView context menu function issue

I'm trying to get the functions within my context menu and button to work, but the file routing for the functions doesn't seem to be working

 

ListView {
                    function getApp() { // 1
                        return _app
                    }
                    
                    id: listView
                    property string selectedItemID
                    dataModel: _app.dataModel
                    
                    listItemComponents: [ // 2
                        
                        ListItemComponent {
                            type: "item"
                            Container {
                                id: itemContainer
                                layout: StackLayout {
                                    orientation: LayoutOrientation.LeftToRight
                                }
                                StandardListItem {
                                    id: rootItem // 3
                                    title: ListItemData.name
                                    description: ListItemData.description
                                                                 
                                    
                                    contextActions: [
                                                  ActionItem {
                                                    
                                                    title: qsTr("Clear All") + Retranslate.onLanguageChanged
                                                    imageSource: "asset:///images/ic_clear_list.png"
                                                    attachedObjects: [
                                                        SystemToast {
                                                            id: clearToast
                                                            body: qsTr("All Items Deleted") + Retranslate.onLanguageChanged
                                                        },
                                                        SystemDialog {
                                                            id: clearDialog
                                                            title: qsTr("Clear List") + Retranslate.onLanguageChanged
                                                            body: qsTr("This action will delete all list items.  This action cannot be un-done.") + Retranslate.onLanguageChanged
                                                            onFinished: {
                                                                if (clearDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection) 
                                                                    rootItem.ListItem.view.getApp().clearObjects() // 4
                                                                
                                                                if (clearDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection)
                                                                    clearToast.show()
                                                            
                                                            
                                                            }
                                                        }
                                                    ]
                                                    onTriggered: {
                                                        clearDialog.show()
                                                    }
                                                },
                                                DeleteActionItem {
                                                    title: qsTr("Delete") + Retranslate.onLanguageChanged
                                                    imageSource: "asset:///images/delete.png"
                                                    attachedObjects: [
                                                        SystemToast {
                                                            id: deleteToast
                                                            body: qsTr("Item Deleted") + Retranslate.onLanguageChanged
                                                        },
                                                        SystemDialog {
                                                            id: deleteDialog
                                                            title: qsTr("Delete Item") + Retranslate.onLanguageChanged
                                                            body: qsTr("This action will delete this item.  This action cannot be un-done.") + Retranslate.onLanguageChanged
                                                            onFinished: {
                                                                if (deleteDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection) 
                                                                    rootItem.ListItem.view.getApp().deleteObject(ListItemData.customerID) // 4
                                                                
                                                                if (deleteDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection)
                                                                    deleteToast.show()
                                                            
                                                            }
                                                        }
                                                    ]
                                                    onTriggered: {
                                                        deleteDialog.show()
                                                    
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                                Label {
                                    text: ListItemData.lat
                                    textStyle.fontSize: FontSize.Large
                                verticalAlignment: VerticalAlignment.Center

                            }
                                Button {
                                    leftPadding: 30
                                    rightPadding: 30
                                    preferredWidth: 150
                                    imageSource: "asset:///images/ic_add.png"
                                    onClicked: {
                                        rootItem.ListItem.getApp().updateObject(ListItemData.customerID, ListItemData.name, ListItemData.description, ListItemData.datefield, ListItemData.lat + 1, ListItemData.lon, ListItemData.categorySelect, ListItemData.mapurl)
                                    }
                                }  
                            }
                        
                        }
                        
                    ]
                    onTriggered: {
                        clearSelection()
                        select(indexPath)
                    
                    
                    }

 

Any help would be greatly appreciated.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView context menu function issue

I don't see any use of files within that code.

 

If you'd like help you're going to have to explain the problem a lot better than that?

 

Have you checked the log for errors?


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: ListView context menu function issue

Agreed, I should've added more information.  I managed to find a work-around.  instead of using a standard list item I just made each item a container.

 

Here's the new working code:

 

ListView {
                    function getApp() { // 1
                        return _app
                    }
                    
                    id: listView
                    property string selectedItemID
                    dataModel: _app.dataModel
                    
                    listItemComponents: [ // 2
                        
                        ListItemComponent {
                            type: "item"
                            Container {
                                id: rootItem
                                rightPadding: 20
                                leftPadding: 20
                                contextActions: [
                                        ActionSet {
                                            title: ListItemData.name
                                            actions: [
                                                ActionItem {
                                                    title: qsTr("Edit") + Retranslate.onLanguageChanged
                                                    imageSource: "asset:///images/ic_edit.png" 
                                                    attachedObjects: [
                                                        Sheet {
                                                            id: editSheet
                                                            
                                                            Page {
                                                                
                                                                id: rootPage
                                                                titleBar: TitleBar {
                                                                    id: editBar
                                                                    title: qsTr("Edit") + Retranslate.onLanguageChanged
                                                                    visibility: ChromeVisibility.Visible
                                                                    
                                                                    dismissAction: ActionItem {
                                                                        title: qsTr("Cancel") + Retranslate.onLanguageChanged
                                                                        onTriggered: {
                                                                            // Hide the Sheet.
                                                                            editSheet.close()
                                                                        }
                                                                    }
                                                                    acceptAction: ActionItem {
                                                                        title: qsTr("Save") + Retranslate.onLanguageChanged
                                                                        onTriggered: {
                                                                            // Hide the Sheet and emit signal that the item should be saved
                                                                            rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, name2.text, ListItemData.description, datefield2.text, counter.text, limittwo.text, ListItemData.categorySelect, ListItemData.mapurl);
                                                                            editSheet.close()
                                                                            editToast.show()
                                                                            name2.text = ""
                                                                            counter.text = ""
                                                                            limittwo.text = ""
                                                                        }
                                                                    }
                                                                }
                                                                
                                                                Container {
                                                                    
                                                                    layout: DockLayout {
                                                                    }
                                                                    //! [0]
                                                                    Container {
                                                                        horizontalAlignment: HorizontalAlignment.Center
                                                                        
                                                                        topPadding: 30
                                                                        leftPadding: 30
                                                                        rightPadding: 30
                                                                        Container {
                                                                            topPadding: 30.0
                                                                            layout: StackLayout {
                                                                                orientation: LayoutOrientation.LeftToRight
                                                                            }
                                                                            
                                                                            TextField {
                                                                                id: name2
                                                                                text: ListItemData.name
                                                                                horizontalAlignment: HorizontalAlignment.Center
                                                                            
                                                                            }
                                                                            Label {
                                                                                id: datefield2
                                                                                text: {
                                                                                    var today = new Date();
                                                                                    (today.getMonth() + 1) + "/" + today.getDate() + "/" + (today.getFullYear() - 2000);
                                                                                }
                                                                            }
                                                                            
                                                                        }
                                                                        Container {
                                                                            layout: StackLayout {
                                                                                orientation: LayoutOrientation.LeftToRight
                                                                            }
                                                                            topPadding: 40
                                                                        
                                                                            TextField {
                                                                                
                                                                                id: counter
                                                                                text: ListItemData.lat
                                                                                
                                                                                inputMode: TextFieldInputMode.NumbersAndPunctuation
                                                                            
                                                                            }
                                                                        TextField {
                                                                            
                                                                            id: limittwo
                                                                            text: ListItemData.lon
                                                                            hintText: qsTr("Limit") + Retranslate.onLanguageChanged
                                                                            inputMode: TextFieldInputMode.NumbersAndPunctuation
                                                                        
                                                                        }
                                                                        
                                                                    }
                                                                        
                                                                        attachedObjects: [
                                                                            SystemToast {
                                                                                id: editToast
                                                                                body: qsTr("Item Edited") + Retranslate.onLanguageChanged
                                                                            }
                                                                        ]
                                                                    }
                                                                    //! [0]
                                                                }
                                                            }
                                                        }
                                                    
                                                    ] 
                                                    onTriggered: {
                                                        editSheet.open()
                                                    }
                                                },
                                                ActionItem {
                                                  title: qsTr("Reset") + Retranslate.onLanguageChanged
                                                  imageSource: "asset:///images/update.png"
                                                  attachedObjects: [
                                                      SystemToast {
                                                          id: restToast
                                                          body: qsTr("Item Count Reset") + Retranslate.onLanguageChanged
                                                      },
                                                      SystemDialog {
                                                          id: resetDialog
                                                          title: qsTr("Reset") + Retranslate.onLanguageChanged
                                                          body: qsTr("This action will reset the item count to one.  You can edit the count afterwards in the edit sheet if you wish.") + Retranslate.onLanguageChanged
                                                          onFinished: {
                                                              if (resetDialog.result == 
                                                              SystemUiResult.ConfirmButtonSelection) 
                                                                  rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, ListItemData.name, ListItemData.description, Date(), 1, ListItemData.lon, ListItemData.categorySelect, ListItemData.mapurl)
                                                              
                                                              if (resetDialog.result == 
                                                              SystemUiResult.ConfirmButtonSelection)
                                                                  resetToast.show()
                                                          
                                                          
                                                          }
                                                      }
                                                  ]
                                                  onTriggered: {
                                                      resetDialog.show()
                                                  }
                                                },
                                                InvokeActionItem {
                                                    title: qsTr("Share") + Retranslate.onLanguageChanged
                                                    query {
                                                        mimeType: "text/plain"
                                                        invokeActionId: "bb.action.SHARE"
                                                    }
                                                    onTriggered: {
                                                        data = ListItemData.name + " count: " + ListItemData.lat + ". Shared using the TiCat app!";
                                                    }
                                                },
                                                
                                                ActionItem {
                                                    
                                                    title: qsTr("Clear All") + Retranslate.onLanguageChanged
                                                    imageSource: "asset:///images/ic_clear_list.png"
                                                    attachedObjects: [
                                                        SystemToast {
                                                            id: clearToast
                                                            body: qsTr("All Items Deleted") + Retranslate.onLanguageChanged
                                                        },
                                                        SystemDialog {
                                                            id: clearDialog
                                                            title: qsTr("Clear List") + Retranslate.onLanguageChanged
                                                            body: qsTr("This action will delete all list items.  This action cannot be un-done.") + Retranslate.onLanguageChanged
                                                            onFinished: {
                                                                if (clearDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection) 
                                                                    rootItem.ListItem.view.getApp().clearObjects() // 4
                                                                
                                                                if (clearDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection)
                                                                    clearToast.show()
                                                            
                                                            
                                                            }
                                                        }
                                                    ]
                                                    onTriggered: {
                                                        clearDialog.show()
                                                    }
                                                },
                                                DeleteActionItem {
                                                    title: qsTr("Delete") + Retranslate.onLanguageChanged
                                                    imageSource: "asset:///images/delete.png"
                                                    attachedObjects: [
                                                        SystemToast {
                                                            id: deleteToast
                                                            body: qsTr("Item Deleted") + Retranslate.onLanguageChanged
                                                        },
                                                        SystemDialog {
                                                            id: deleteDialog
                                                            title: qsTr("Delete Item") + Retranslate.onLanguageChanged
                                                            body: qsTr("This action will delete this item.  This action cannot be un-done.") + Retranslate.onLanguageChanged
                                                            onFinished: {
                                                                if (deleteDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection) 
                                                                    rootItem.ListItem.view.getApp().deleteObject(ListItemData.customerID) // 4
                                                                
                                                                if (deleteDialog.result == 
                                                                SystemUiResult.ConfirmButtonSelection)
                                                                    deleteToast.show()
                                                            
                                                            }
                                                        }
                                                    ]
                                                    onTriggered: {
                                                        deleteDialog.show()
                                                    
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                Container {
                                    id: rootItemtwo
                                    layout: StackLayout {
                                        orientation: LayoutOrientation.TopToBottom
                                    }
                                
                                Container {
                                    id: rootItemthree
                                    layout: StackLayout {
                                        orientation: LayoutOrientation.LeftToRight
                                    }
                                
                                Label {
                                    
                                    preferredWidth: 450
                                    text: ListItemData.name
                                    textStyle.fontSize: FontSize.Large
                                }
                                Label {
                                    
                                    minWidth: 100.0
                                    preferredWidth: 100.0
                                    maxWidth: 120
                                    text: ListItemData.lat
                                    textStyle.fontSize: FontSize.Large
                                verticalAlignment: VerticalAlignment.Center
                                

                            }
                                Label {
                                    translationY: 5
                                    text: "/" + ListItemData.lon
                                    textStyle.fontSize: FontSize.Small
                                    verticalAlignment: VerticalAlignment.Center
                                    
                                    textStyle.color: Color.DarkGray
                                        minWidth: 100.0
                                        preferredWidth: 100.0
                                    }
                                Button {
                                    leftPadding: 30
                                    rightPadding: 30
                                    preferredWidth: 150
                                    horizontalAlignment: HorizontalAlignment.Center
                                    imageSource: "asset:///images/ic_add.png"
                                    onClicked: {
                                        
                                        rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, ListItemData.name, ListItemData.description, ListItemData.datefield, parseInt(ListItemData.lat) + 1, ListItemData.lon, ListItemData.categorySelect, ListItemData.mapurl)
                                    }
                                } 
                                }
                                
                                
                                Label {
                                    translationY: -20
                                    minWidth: 600
                                    preferredWidth: 600
                                    text: "Last Count: " + ListItemData.datefield
                                    textStyle.fontSize: FontSize.XSmall
                                    textStyle.color: Color.DarkGray
                                    horizontalAlignment: HorizontalAlignment.Left
                                }
                                
                                Divider {
                                    translationY: -20
                                }
                            } 
                                bottomPadding: 5
                                
                            }
                        
                        }
                        
                    ]
                    onTriggered: {
                        clearSelection()
                        select(indexPath)
                    }
                }
            }

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView context menu function issue

Glad you've fixed it.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.