Search code examples
androidandroid-linearlayout

Disable all edittext inside linear layout


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?


Solution

  • 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);
            }
        }