I am trying to disable all field inside linear layout. There are many edittext and textview inside that linear layout. However, i am only trying to disable edittext. I was able to disable all children but i want able to disable on edit text. Is there any way to do that?
Where ll is your linearlayout:
LinearLayout ll = (LinearLayout) findViewById(R.id.myLLid);
for (View view : ll.getTouchables()){
if (view instanceof EditText){
EditText editText = (EditText) view;
editText.setEnabled(false);
editText.setFocusable(false);
editText.setFocusableInTouchMode(false);
}
}
The recursivity is the easiest way to do that. More secure to catch them all.
private void setAllEditTextEnabled(@NonNull View view, boolean enable){
if (view instanceof EditText) {
view.setEnabled(enable);
}
else if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View innerView = ((ViewGroup) view).getChildAt(i);
setAllEditTextEnabled(innerView, enable);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With