Reputation: 107
I have an app that downloads and passes image to ImageView. Now I need to hide button after few seconds after this operation when user is not doing any actions (eg. just looking on downloaded image). How can I achieve that?
Upvotes: 2
Views: 2914
Reputation: 2359
You can try doing something like this:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
nameOfButton.setVisibility(View.GONE);
}
}, 5000);
5000 is in milliseconds which equals to 5 seconds in this case.
Note: Do not use threads like Thread.sleep(5000); because it blocks your UI and makes it unresponsive.
Upvotes: 3
Reputation: 27505
You can use Handler
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// hide your button here
btn.setVisibility(View.GONE);
}
}, YOUR_TIME_IN_MILISECONDS);
Upvotes: 6