I haven't written a blog for a long time. Today I want to share with you a small function that is very practical.
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.
CodeAs follows:
/*** Traverse the layout and disable all child controls ** @ Param viewgroup * layout object */public static void disablesubcontrols (viewgroup) {for (INT I = 0; I <viewgroup. getchildcount (); I ++) {view v = viewgroup. getchildat (I); If (V instanceof viewgroup) {If (V instanceof 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 ");}}}