The grid view gets the elements that are visible to the user.

I display the images in a grid [about 100 images] and these images will be updated in 10 seconds. I want to update only those images that are visible to the user. How can I get only visible elements from the grid view, so I can ask the server to get only those images that are visible to the user?

+4
source share
2 answers
for(int i = 0; i < GridView.getChildCount(); i++) { if(GridView.getChildAt(i).isVisible()) // do what you need } 

You should consider that this is an abstract code snippet, just an illustrated approach to solve your problem.

Edit: The best way, in my opinion:

 for(int visiblePosition = GridView.getFirstVisiblePosition(); visiblePosition <= GridView.getLastVisiblePosition(); visiblePosition++) { View view = GridView.getChildAt(visiblePosition); // make something } 
+8
source

You can simply call: gridView.getFirstVisiblePosition () gridView.getLastVisiblePosition ()

I did what I wanted. Therefore, I used this only to obtain the required images.

+3
source

Source: https://habr.com/ru/post/1379443/


All Articles