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

可紊 提交于 2019-12-11 02:13:30

问题


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);
    }
}

回答1:


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
            }            
        }        
]


来源:https://stackoverflow.com/questions/14138094/how-to-implement-the-button-click-event-on-listview-in-blackberry-10-cascades-qm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!