【问题标题】:How to get source properties on button click inside list view ? [Andorid Appcelerator]如何在列表视图内单击按钮获取源属性? [安卓应用加速器]
【发布时间】:2016-07-02 08:37:12
【问题描述】:

我在项目内有带有按钮的列表视图。我已经设置了一个点击事件函数,但它不返回点击按钮的属性。在 iOS 中它运行良好。

    var item = {
    properties : {
        accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE,
        backgroundColor: '#fff',
        width: Ti.UI.FILL,
        height : Ti.UI.SIZE
    },
    events: {
       click: eventFunction
    },
    childTemplates : [
    {
        type : 'Ti.UI.Button',
        bindId : 'bindButton',
        properties : {
            width: 70,
            height: 70,
            image: "/images/user_icon.png",
            borderRadius: 35,
            borderWidth: 1,
            borderColor: '#dedede',
            zIndex: 1,
            backgroundColor: 'transparent',
            idButton : 10
        }

当我单击 eventFunction 中的按钮时,我希望找到 e.source.idButton 但 e.source 不包含它。为什么?在 iOS 中,我找到了预期的属性。 我试过在按钮模板中移动事件参数,但结果是一样的。

【问题讨论】:

    标签: android listview events button appcelerator


    【解决方案1】:

    在我的列表视图中,我只听“itemclick”事件。 所以我现在的代码是这样的:

    listView.addEventListener('itemclick',function(e){
        var item = listView.getSections()[0].getItemAt(e.itemIndex);
        if(e.bindId === 'blockIcon'){
            //do my stuff
        }
    

    如果这对你有帮助,请告诉我

    【讨论】:

    • 您好,感谢您的留言。就我而言,它不起作用,因为我有 n 个动态生成的按钮,并且每次单击都需要获取属性才能知道我单击了哪个按钮。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    相关资源
    最近更新 更多