Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You will have to add an <code>OnHierarchyChangeListener</code> to your listview so that you can get the value of new height of the listview when child items are added to or removed from the list :</p> <pre><code>lv_marca.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() { @Override public void onChildViewRemoved(View parent, View child) { // This will give you the height when your new adapter contains // lesser number of items than the previous one int heightAfterItemRemoved=parent.getHeight(); Log.i("list_view_height_change","Height after removing item : "+heightAfterItemRemoved); } @Override public void onChildViewAdded(View parent, View child) { // This will give you the height when your new adapter contains // greater number of items than the previous one int heightAfterItemAdded=parent.getHeight(); Log.i("list_view_height_change","Height after adding item : "+heightAfterItemAdded); } }); </code></pre> <p>There is a catch - this will only work if your list view's 'layout_height' property is set to 'wrap_content'. In this case, the height of the list view increases or decreases as items are added or removed, respectively. The list view's height reaches the maximum value when the list view is completely filled. If you add more items to the list view, it will overflow and be scrollable, but the height value will not change, as it is already occupying the maximum permissible height within its parent view. <br/> <br/> If you set 'layout_height' to 'fill_parent' or 'match_parent', the list view will occupy the maximum permissible height within its parent view from the very start and hence, removing or adding items to it will not result in any change in its height.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload