如何在Blackberry 10级联QML的ListView上实现Button click事件? [英] How to implement the Button click event on listview in blackberry 10 cascades qml?

查看:139
本文介绍了如何在Blackberry 10级联QML的ListView上实现Button click事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的列表视图,但是无法触发qml blackberry 10中按钮的click事件?有人可以帮我解决这方面的问题吗,

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

推荐答案

我怀疑这可能是与您粘贴的代码之外的内容有关的问题,但是您可以尝试以下方法作为onclicked的替代方法,该方法可能会起作用更适合您.

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

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

这篇关于如何在Blackberry 10级联QML的ListView上实现Button click事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆