Use Case: Disable all the child controls in the layout so that the interface can only be viewed but not edited. It is very troublesome to set one control, so I thought of a good method. You can expand more controls as needed, as long as you pay attention to the ViewGroup type or View type of the control.
The Code is as follows:
/*** Traverse the layout and disable all child controls ** @ param viewGroup * layout object */public static void disableSubControls (ViewGroup viewGroup) {for (int I = 0; I <viewGroup. getChildCount (); I ++) {View v = viewGroup. getChildAt (I); if (v instanceof ViewGroup) {if (v instanceof Spinner) {Spinner spinner = (Spinner) v; spinner. setClickable (false); spinner. setEnabled (false); Log. I (TAG, "A Spinner is unabled");} else if (v instanceof ListView) {(ListView) v ). setClickable (false); (ListView) v ). setEnabled (false); Log. I (TAG, "A ListView is unabled");} else {disableSubControls (ViewGroup) v) ;}} else if (v instanceof EditText) {(EditText) v ). setEnabled (false); (EditText) v ). setClickable (false); Log. I (TAG, "A EditText is unabled");} else if (v instanceof Button) {(Button) v ). setEnabled (false); Log. I (TAG, "A Button is unabled ");}}}