gkopowski
gkopowski

Reputation: 107

Android - how to hide button after few seconds of inactivity

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

Answers (2)

Edward
Edward

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

N J
N J

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

Related Questions