ios - Titanium:向 listView 添加一个 ActivityIndi​​cator?

标签 ios listview titanium selectlistitem activity-indicator

http://docs.appcelerator.com/titanium/3.0/?mobile=/api/Titanium.UI.ActivityIndicator

是否可以以及如何将 ActivityIndi​​cator 添加到 listView listItem?可能通过所选项目上的 listView 模板...

提前致谢!

最佳答案

是的,这是可能的,这是一个片段:

  1. 首先从定义列表项模板开始:

    // Some text row 
    var someTextTemplate = {
        properties: {
            accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE
        },
        childTemplates: [ // Add view subcomponents to the ListItem
            {
                // Display a Label
                type: 'Ti.UI.Label',
                bindId: 'someRowText',
                properties: {
                    font: {fontSize: '14dp'}
                }
            }
        ]
    };
    
    //This is your loading template
    var loadingTemplate = {
        properties: {
            accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE
        },
        childTemplates: [ //And here is where the activity indicator goes
        {
            // Display an activity indicator
            type: 'Ti.UI.ActivityIndicator',
            // If there is a 'loadingIndicator' dictionary in the ListDataItem,
            // that data binds with this view subcomponent (useful for changing
            // the loading message, for example)
            bindId: 'loadingIndicator', 
            properties: {
                // Set the indicator properties
                font: { fontSize: '22dp'},
                width: Titanium.UI.SIZE,
                height: Titanium.UI.SIZE,
                // If you don't set visible to true, the indicator will not show,
                // because unlike other UI elements, it is hidden by default
                visible: true, 
                //Other styles available, just check the component doc      
                style: Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN
            }
        }
        ]
    };
    
  2. 然后设置您的 ListView

    // Create the list section
    var listSection = Titanium.UI.createListSection();
    
    // Add the list section to a list view
    var listView = Titanium.UI.createListView({
        width: Ti.UI.FILL,
        height: Ti.UI.SIZE,
        layout: 'vertical',
        touchEnabled: true,
        sections: [listSection],
        templates: {'rowText': someTextTemplate, 'loading': loadingTemplate },
        defaultItemTemplate: 'rowText',
        showVerticalScrollIndicator: true
    });
    
  3. 最后,添加一些列表数据项

    var someData = [];
    // This will add a row with a label, because we've set 'rowText' as our 
    // default ListView template
    someData.push({
        someRowText: { text: 'Some text row 1'}
    });
    // This will also show another label row, because we're specifying 
    // the template to use, in this case the label one
    someData.push({
        someRowText: { text: 'Some text row 2'},
        template: 'rowText'
    });
    // Now we're going to use the 'loading' template, therefore showing 
    // the activity indicator in the row
    someData.push({
        loadingIndicator: { message: 'Please wait while transfering data from the mothership...' },
        template: 'loading'
    });
    
    //Add our data items to the listview section
    listSection.setItems(someData);
    

您也可以混合使用多个模板,但我已尽量简化示例。

关于ios - Titanium:向 listView 添加一个 ActivityIndi​​cator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24667048/

相关文章:

Android: ListView 闪烁效果。关于如何摆脱这个的任何提示?

wpf - 如何使 WPF ListView 项目水平和垂直重复?

ios - Titanium Facebook 模块问题

php - 如何在 Titanium (Android) 中以 jpg 或 png 格式在服务器上上传图像?

javascript - 添加 View 以打开钛窗口

ios - 重新加载数据时刷新 tableView 闪烁

ios - 导航 Controller 始终为零

android - 避免多次点击

ios - 从字典中设置 UIlabel 属性名

ios - Cordova 插件 - 如何使用 build.json