Android automatically disables all child controls in the layout

Source: Internet
Author: User

Use scene: Disable all the child controls in the layout, so that the interface can only see, but can not edit, if a control to set up is certainly very troublesome, so think of a good method. You can extend more controls as needed, as long as you are aware that the control is ViewGroup type or view type.

The code is as follows:

/** * Traverse layout and Disable all child controls * * @param viewgroup * Layout object/public static void D Isablesubcontrols (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"); }
		}
	}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.