14

I have an adapter that connected to ListView, e.g.

mJournalAdapter = new JournalAdapter();
journalEntryList.setAdapter(mJournalAdapter);

and I want to know inside of my JournalAdapter if some view (item of ListView) is visible or not, is it possible?

olegflo
  • 1,105
  • 3
  • 17
  • 26

3 Answers3

24

If you know the postion of that item then you can use

int last = listView1.getLastVisiblePosition();  

int first = listView1.getFirstVisiblePosition();
Twometer
  • 1,561
  • 2
  • 16
  • 24
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
6

You can get callback , overriding OnDetachedFromWindow(); method in View

dooplaye
  • 999
  • 13
  • 28
  • That's not how you are supposed to do in the `ListView`. You're reinventing the wheel. The other 2 answers are legit. – Sufian May 15 '14 at 05:29
  • It's not reinventing the wheel. In fact, it is very a nice way to handle view recycling de-coupled from the listview/recyclerview/adapter – Vedant Agarwala Mar 27 '16 at 12:23
2

You can use getFirstVisiblePosition() will give you the first visible Item in the ListView, so you can use that in your case.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242