Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide the button and show again on touch

I am working on an application where I want to hide the button, or, say, make the button invisible when I touch the screen and again make the button visible when I again touch the screen.

How I can make it?

like image 402
David Brown Avatar asked Jun 04 '11 09:06

David Brown


Video Answer


1 Answers

Implement an onTouchListener

 // Catch touch events here
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        System.out.println("Touch Down X:" + event.getX() + " Y:" + event.getY());
    } 
    if (event.getAction() == MotionEvent.ACTION_UP) {
        System.out.println("Touch Up X:" + event.getX() + " Y:" + event.getY());
    }
    return super.onTouchEvent(event);
}

Then in this you'll want to reference the button and set it's visibility:

  button1.setVisibility(View.VISIBLE); or View.INVISIBLE
like image 130
Blundell Avatar answered Sep 21 '22 07:09

Blundell