Disable the touch events for all the views Disable the touch events for all the views android android

Disable the touch events for all the views


Here is a function for disabling all child views of some view group:

 /**   * Enables/Disables all child views in a view group.   *    * @param viewGroup the view group   * @param enabled <code>true</code> to enable, <code>false</code> to disable   * the views.   */  public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {    int childCount = viewGroup.getChildCount();    for (int i = 0; i < childCount; i++) {      View view = viewGroup.getChildAt(i);      view.setEnabled(enabled);      if (view instanceof ViewGroup) {        enableDisableViewGroup((ViewGroup) view, enabled);      }    }  }


Override the dispatchTouchEvent method of the activity and like this:

@Overridepublic boolean dispatchTouchEvent(MotionEvent ev){        return true;//consume}

If you return true all touch events are disabled.

Return false to let them work normally


You could try:

your_view.setEnabled(false);

Which should disable the touch events.

alternatively you can try (thanks to Ercan):

@Overridepublic boolean dispatchTouchEvent(MotionEvent ev){        return true;//consume}

or

public boolean dispatchTouchEvent(MotionEvent ev) {    if(!onInterceptTouchEvent()){        for(View child : children){            if(child.dispatchTouchEvent(ev))                return true;        }    }    return super.dispatchTouchEvent(ev);}