Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable all user inputs (click, touch) on an android view

I have a game view which is an extension of View class. In this view I use canvas drawing objects, which the users can interact with.

This view loaded to the layout of an activity. I want to disable all user inputs to the game view, when a button is clicked in the layout.

I tried using

gameView.setEnabled(false);
gameView.setClickable(false);

But still the user can interact with the canvas objects.

FYI : Gameview class implements following interfaces as well.

public class Gameview extends View implements OnGestureListener,
        OnDoubleTapListener, OnScaleGestureListener, AnimationListener 
like image 545
pats Avatar asked Oct 27 '14 11:10

pats


People also ask

How do I turn off touch screen on Android?

To use the Touch Lock app, launch the app and then tap Start Service. You'll notice that the app icon appears in your notification bar. Next, head to the app you want to use, and when you're ready to lock the screen, pull down the notification bar and tap Lock Touch. Your phone screen will now be disabled.


1 Answers

You can do this:

gameView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});

It will capture all user input, and if you return true, it will stop here. If you return false it will assume that you have not handled the event and pass it on to the next listener. You can have a boolean variable that you set to true / false when you need to enable / disable your view.

like image 137
Squeazer Avatar answered Sep 23 '22 02:09

Squeazer