How can I detect listView item to change or make some actions when it was scrolled above the center of screen?
UPD Solution
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
int half = visibleItemCount/2;
int to = firstVisibleItem+half;
for (int i=firstVisibleItem; i<to; i++) {
// actions for item above center
Item item = (Item)adapter.getItem(i);
item.read = true;
}
adapter.notifyDataSetChanged();
}
You can achieve this using a combination of methods. If your ListView stretches the whole screen (i.e., height is set to MATCH_PARENT), you can determine the center of your screen as the total number of children / 2. Use the getChildCount() method for this job.
As Ayoub said, you can also use a ListView.OnScrollListener to listen for scroll changes in your ListView.
In case your ListView's height does not match the available window screen, you can use this to find the available window height:
DisplayMetrics metrics = getResources().getDisplayMetrics();
int windowWidth = metrics.widthPixels;
int windowHeight = metrics.heightPixels
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With