Skip to content Skip to sidebar Skip to footer

How To Get Height Of The Item In A Listview?

I am using a customadapter and overriding the getView() method. In this method I call view.getHeight() which returns 0. I would like to find out the height (in pixel) of each item

Solution 1:

You might need to use something like the ViewTreeObserver. Please see this question's response. You can place a block similar to this in your onCreate method. If a view is returning a value of 0 it is most likely that your are calling the view method too early in the activity lifecycle (ie before the screen objects are mapped out and able to be measured).

Solution 2:

For a given VISIBLE row nPosition in list mList, you can get the location of the view via:

// find the position of the source and destination accounts ListView rowsint[] location = {0,0};

ViewviewList= mList.getChildAt(nPosition - mList.getFirstVisiblePosition());
viewList.getLocationOnScreen(location);

but you'll likely need to do this from outside your getView(), i.e. after the list is populated.

Post a Comment for "How To Get Height Of The Item In A Listview?"