Add labels dynamically into a view in a ListViewItem

444 views Asked by At

In Appcelerator Titanium, I have following XML for my ListView example:

<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"/>

I'm using following code to return some data to populate my 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'
    })]}
}

This is some demo data, but this code results into different behavior on Android then on iOS.

On iOS, I get the expected result. The 'envelopes' view is a green rectangle containing the label 'first'. On Android, this doesn't seem to work. I only get the green rectangle, but the children(s) are not added.

Someone who knows how to fix this Android-specific issue? How to add labels to a view in a listview?

When adding a label to envelopes using XML (in between the <View> and </View>), the label is shown. When trying to add it using the children-property, the label is not added to the view.

1

There are 1 answers

0
rjcpereira On BEST ANSWER

The children property it's not supposed to work, but in iOS it does.

I've faced the same issue, the only solution for work in android was to include the label in the template.

I've created this question that relates to that: Get bindId from added data to an TableView inside a ListView (Titanium/Alloy), in that case I've also tried setting the data to a TableView that way but still no success.

Either way, this is not recommended.

In your case I think that you don't need, but if you want to know the selected bindId, you can't, only the views and labels that are defined in the ItemTemplate (using Alloy)