AlexDot
AlexDot

Reputation: 13

How can I check if a View is visible (android listview)

I've created a library that allows user to download images in background and put it in a View, passed by argument to a function, when download is finished. The problem is that if I use my library in a listview, calling this method in the getView() method, when a user scroll very fast, the library do a request for each row passed. But I'd like to do it, only when a cell is really visible by user... maybe when the scroll list is stopped. So, how can I check this thing on the single view that I pass to the library method? Thaaanks

Upvotes: 1

Views: 4800

Answers (2)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75798

You can use

  1. getVisibility () Returns the visibility status for this view .

  2. isShown () Returns the visibility of this view and all of its ancestors .

getVisibility()

 if (ViewObj.getVisibility() == View.VISIBLE) {
    // Your Staff
} else {
   // Your Staff
}

isShown ()

True if this view and all of its ancestors are VISIBLE

Upvotes: 4

Spirrow
Spirrow

Reputation: 1150

You can use view.getVisibility(). The result will be View.VISIBLE, View.GONEor View.INVISIBLE.

If you want to do something when your view is visible, then your expected result will be: View.VISIBLE

if(yourView.getVisibility() == View.VISIBLE){
//Do what you want..
}

Upvotes: 0

Related Questions