如何在blackberry 10级联qml的listview上实现Button click事件?

时间:2013-01-03 11:31:25

标签: qml blackberry-10 blackberry-cascades

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

 
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 个答案:

答案 0 :(得分:3)

我怀疑这可能与您粘贴的代码之外的某些问题有关,但您可以尝试使用以下内容作为onclicked的替代方案,这可能对您有用。

如果以下两个选项都不起作用,那么您需要检查控制台日志中是否有可能导致它的任何内容。

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