0

I would like to be able to determine the height of a listview prior to adding items. The listview is defined as layout_height=0dp and layout_weight=5 (or some other value, its not fill_parent or wrap_content). When I call lv.getHeight prior to adding items, the height returns 0. I've tried using lv.requestLayout() and lv.getMeasuredHeight in the onResume method of my fragment.

Things I've tried so far: Querying the listview height in an onGlobalLayout handler. This gets me the correct height, but the listadapter's getView has already been called to populate the list. If I wait to bind the adapter until after onGlobalLayout, then when I use adapter.notifyDataSetChanged() to update the view, I'm stuck in a loop of onGlobalLayout handler calls.

From the docs, onResume appears to be called after the layout is complete, so I would expect that the listview.getHeight or listview.getMeasuredHeight would return valid values at this time, but all I get is 0.

Why I want this. I need to know how many items will fit in the listview prior to adding them. I want to add a number (count-1) of "blank items" at the top of the list so that it is possible for the user to scroll the top item in the list to the bottom so it is visually next to another control below the list.

John B
  • 13
  • 5

1 Answers1

0

Finally found this.
View's getWidth() and getHeight() returns 0 But it appears to be counter to the documentation of onResume

John B
  • 13
  • 5