Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do ListView's getFirstVisiblePosition and getLastVisiblePosition lie?

I've got my ListView on screen. It's scrolled to the top. I see 6 rows. And when I Log getFirstVisiblePosition() and getLastVisiblePosition(), it says 0 and 6.

Is getLastVisiblePosition() actually returning the first non-visible position? In other words, should my test for whether a particular row is onscreen be not

first <= row && row <= last

but rather

first <= row && row < last

?

like image 759
Carl Manaster Avatar asked Nov 15 '22 08:11

Carl Manaster


1 Answers

Well, probably there is the portion of last visible view number 6 in your case, that is actually detected as visible (maybe just a tiny part appears on the bottom of the screen). But in any case if it shows that the count is 7, why not go with it? I mean whatever you do to that row won't actually be seen, plus the view is already bound in the adapter and the getView method in the adapter wont be called again.

One more thing with your second code is that, for example, when you have only one view then the first will be 0, row will be 0 and last will be 0 and your conditions won't be met. Don't know if this helps you in any way but still...

like image 127
DArkO Avatar answered May 22 '23 16:05

DArkO