Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force onSizeChanged for ListView

I have a listview which gets assigned with different datasets dynamically. This works fine. I have also made fastScrollEnabled to be true. For the sectionIndexer to be updated I need to call

list.setFastScrollEnabled(false);
list.setFastScrollEnabled(true);

The problem is the index shows in top left and this is a know issue. As a work-around whenever I change the orientation the index is again correctly shown. To test this I have implemented a custom ListView and the observation is if I can force listView to call onSizeChanged() it will show up properly.

Now the question:

Is it possible to force listView to call onSizeChanged() method? If yes how can we accomplish this.

Does anyone know of conditions when onSizeChanged() is called. It is definitely called when the orientation changes, any other conditions we can think of.

like image 939
PravinCG Avatar asked May 26 '11 15:05

PravinCG


1 Answers

To force onSizeChanged on ListView I do the following:

myList.getLayoutParams().height = myList.getHeight() + 1;
myList.requestLayout();

Just be sure to not call +1 or -1 everytime as the list may just overstretch the size specified and hence use a flag to toggle between +1 and -1.

like image 154
PravinCG Avatar answered Sep 19 '22 00:09

PravinCG