arnp
arnp

Reputation: 3208

Can i extend the size of a listview dynamically in java code

I am using a listview in a layout with a size- not in full size of layout. Below the layout there are components like button. I need the layout to get extended when more number of listitems adds dynamically.

I have kept the listview and buttons in scrollview.

Is there any attribute or option to make listview of variable length

Upvotes: 3

Views: 268

Answers (2)

Ron
Ron

Reputation: 24235

You should not have a listview inside a scrollview. Instead of having a listview you should add your items to a linearlayout, which will grow to accomodate the items and not enable the scrollbar within itself. This will solve your UI issue. You can set the onclickListeners in a for looop.

Update

<ScrollView.....>
    <LinearLayout .....>
       <LinearLayout ..../> // this has your list items
       <Button .... /> // you can have a layout here if you have multiple buttons.
    </LinearLayout>
</ScrollView>

Upvotes: 1

K-ballo
K-ballo

Reputation: 81349

Set the ListView's layout_height value to wrap_content, and it will stretch to accomodate all the items' views in its adapter.

Upvotes: 0

Related Questions