【问题标题】:Add labels dynamically into a view in a ListViewItem将标签动态添加到 ListViewItem 中的视图中
【发布时间】:2017-01-04 19:06:31
【问题描述】:

在 Appcelerator Titanium 中,我的 ListView 示例有以下 XML:

<ListView class="fill-height" defaultItemTemplate="item">
<Templates>
    <ItemTemplate name="item" height="100dp">
        <View class="top-10 left-10 right-10 bottom-10" layout="vertical">
            <View class="size-height fill-width">
                <Label class="left title" bindId="name"/>
                <Label class="right description" bindId="number"/>
            </View>
            <Label class="top-5 left fill-width description" height="13dp" bindId="direction"/>
            <View width="100dp" height="40dp" layout="vertical" backgroundColor="green" bindId="envelopes">
            </View>
        </View>
    </ItemTemplate>
</Templates>

<ListSection id="items"/>

我正在使用以下代码返回一些数据来填充我的 ListView:

return {
    name: {text: object.name},
    number: {text: object.number},
    direction: {text: object.direction},
    envelopes: { children: [Titanium.UI.createLabel({
        text: "first",
        width:'30dp',
        height:'30dp'
    })]}
}

这是一些演示数据,但这段代码在 Android 和 iOS 上会导致不同的行为。

在 iOS 上,我得到了预期的结果。 “信封”视图是一个包含标签“first”的绿色矩形。在 Android 上,这似乎不起作用。我只得到绿色矩形,但没有添加孩子。

知道如何解决这个 Android 特定问题的人吗?如何将标签添加到列表视图中的视图?

使用 XML 向信封添加标签时(在&lt;View&gt; 和&lt;/View&gt; 之间),会显示标签。尝试使用 children-property 添加它时,标签不会添加到视图中。

【问题讨论】:

    标签: android titanium-mobile appcelerator-titanium titanium-alloy appcelerator-alloy


    【解决方案1】:

    children 属性不应该工作,但在 iOS 中可以。

    我也遇到过同样的问题,在 android 中工作的唯一解决方案是在模板中包含标签。

    我已经创建了与此相关的问题:Get bindId from added data to an TableView inside a ListView (Titanium/Alloy),在这种情况下,我也尝试过以这种方式将数据设置为 TableView,但仍然没有成功。

    无论如何,不​​建议这样做。

    在你的情况下我认为你不需要,但是如果你想知道所选的 bindId,你不能,只有在 ItemTemplate 中定义的视图和标签(使用 Alloy)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      • 2011-09-07
      • 2021-09-03
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多