View.setEnabled(false) does not work quite right in android -


i found out view.setenabled(false) not work quite right in android, in following ways:

  1. disable parent view not automatically disable child views. inconvenient.
  2. though grayed in color, disabled views can still focus , keyboard input, make choice, etc. not right.
  3. when getting keyboard input, del/back can remove 1 key backward no matter how many input. behavior shows in disabled edittext.
  4. radio label grayed radio button image not grayed.

it seems bug. how real disable feature?

edit: forget mention first.

recursively setting descendants needed, otherwise radiobuttons in layout not setenabled because radiobuttons grand-children not direct children, there radiogroup in between. record best solution far here based on others' answer.

public static void setenabledall(view v, boolean enabled) {     v.setenabled(enabled);     v.setfocusable(enabled);      if(v instanceof viewgroup) {         viewgroup vg = (viewgroup) v;         (int = 0; < vg.getchildcount(); i++)             setenabledall(vg.getchildat(i), enabled);     } } 

subclass not working @ time. if have:

public myview class view {     protected void setenabled(boolean enabled, boolean setchildren){         setenabled(enabled);         setfocusable(enabled);         if(setchildren && isinstanceof viewgroup){               ( int = 0 ; < this.getchildcount() ; i++ )                   //this line have issue if not myview                                         this.getchildat(i).setenabled(enabled, true);          }     } } 

unless view has overloaded setenabled this:

public class view {     protected void setenabled(boolean enabled, boolean setchildren){         setenabled(enabled);         setfocusable(enabled);         if(setchildren && isinstanceof viewgroup){               ( int = 0 ; < this.getchildcount() ; i++ )                            this.getchildat(i).setenabled(enabled, true);          }     } } 

this solution eliminate problems 1, 2, 3. problem 4 can solved setting disabled style selector radiogroup - not sure why android has no default disabled style selector radiogroup. maybe point android enhancement. android flexible in sdk design means work needed.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -