views:

35

answers:

2

The following code display a list of comments using List control. The item height set to a fixed value (150), so it seems working: if the content is too long, the scrollbar shows...

However, what I really want is not to set the height but let it to change according to the content size. Is there any way to accomplish this?

        <mx:List id="commentList" width="100%" dataProvider="{commentSet.commentArrayColl}"
            rowCount="{commentSet.commentArrayColl.length}" >
            <mx:itemRenderer>
                <mx:Component>
                    <mx:VBox width="100%" height="150" >
                        <mx:Text text="{data.commentContent}" />
                        <mx:Text text="{data.username} ({data.modified})"/>
                    </mx:VBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:List> 

EDIT: To be more clear, I don't want to set the itemRenderer's VBox height to "150" or any other fixed value - but it'll only show one line of the text if I don't do it. So I'm looking for a way out of this. (If the VBox is not inside the itemRenderer, it'll auto ajust height as Text field string length grows - that's what I want.)

+2  A: 

Add a height property that binds a function of dataProvider.length * 150:

    <mx:List id="commentList" width="100%" dataProvider="{commentSet.commentArrayColl}"
        rowCount="{commentSet.commentArrayColl.length}" height={commentSet.commentArrayColl.length*150}>
        <mx:itemRenderer>
            <mx:Component>
                <mx:VBox width="100%" height="150" >
                    <mx:Text text="{data.commentContent}" />
                    <mx:Text text="{data.username} ({data.modified})"/>
                </mx:VBox>
            </mx:Component>
        </mx:itemRenderer>
    </mx:List>
John Drummond
No. The problem is the height of the "List Item" -- list itemReferer, not the "List" iteself. (The above code is actually doing the same as the original one.)
joejax
Then do what bug-a-lot said: variableRowHeight="true" on the List and remove the VBox height property.
John Drummond
+1  A: 

Try not setting the height on the VBox, and variableRowHeight to true on the list. Although I'm not sure how nice the List would play with that.

Alternatively, since you're not really using the advantage of itemRender recycling (because of rowCount = dataProvider.length) you might want to consider using a repeater instead of the list.

bug-a-lot
variableRowHeight seems not working, but Repeater is almost a perfect solution until I got the problem in editing the item: I make the repeater display a list of Text, and once clicked it switched to TextArea so it can be edit. Repeater is not easy to get the selected item like List. (I got Error: Repeater is not executing)
joejax
Well, if you want selection with a repeater, you'll need to implement it yourself. What the repeater does is just add the components to the container, and after that you're on your own.
bug-a-lot