SelvaRaman
SelvaRaman

Reputation: 218

How to implement the Button click event on listview in blackberry 10 cascades qml?

I have a list view with buttons but am not able to triggered the click event for buttons in qml blackberry 10 ? Can anyone help me about this regards,

ListView {
    verticalAlignment: VerticalAlignment.Center
    horizontalAlignment: HorizontalAlignment.Center
    layout: FlowListLayout {
    }
    dataModel: mydatamodel
    listItemComponents: [
        ListItemComponent {
            type: "item"
            Container {
                layout: DockLayout {
                }

                Button {
                    id: samplebutton
                    text: "Button"
                    horizontalAlignment: HorizontalAlignment.Right
                    onClicked: {
                        //click event not fired here..
                    }
                }
                Label {
                    horizontalAlignment: HorizontalAlignment.Left
                    text: "Sample Label"
                }
                Divider {
                    horizontalAlignment: HorizontalAlignment.Fill
                }
            }
        }
    ]
    onTriggered: {
        var selectedItem = dataModel.data(indexPath);
    }
}

Upvotes: 2

Views: 1304

Answers (1)

hyarion
hyarion

Reputation: 2251

I suspect it may be an issue related to something outside of the code you've pasted, but you can try the following as alternatives for the onclicked which may work better for you anway.

If neither of the below options work then you need to check your console logs for anything that might be causing it.

onTouch: {
  if (event.isUp()) {
    //do stuff here
  }
}

or

gestureHandlers: [
    gestureHandlers: [
        TapHandler {
            onTapped: {
                 //do stuff.  This is equivalent to an onClick
            }                
        },
        LongPressHandler {
            onLongPressed: {
                //do stuff when user holds down
            }            
        }        
]

Upvotes: 3

Related Questions