Skip to content

Instantly share code, notes, and snippets.

@laaptu
Created September 17, 2013 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laaptu/6591247 to your computer and use it in GitHub Desktop.
Save laaptu/6591247 to your computer and use it in GitHub Desktop.
Method to disable or enable child view of a view group or view
/**
*http://stackoverflow.com/questions/5418510/disable-the-touch-events-for-all-the-views
* 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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment