java - Edittext change Border Color always onclick -



have edittext , want change border color after onclick.
after click on it shows me red border color.
after try again nothing happens. still red.
first click red -> second click black -> third click red , on
how can fix it?

... boolean focus = false  ...     private void setonfocuschangelistener(final edittext edittext) {                                    edittext.setonfocuschangelistener(new view.onfocuschangelistener() {             @override             public void onfocuschange(view view, boolean hasfocus) {                 if (!hasfocus) {                     edittext.setbackgroundresource(r.drawable.black);                     focus = false;                 } else if (hasfocus) {                     edittext.setbackgroundresource(r.drawable.red);                     focus = true;                 } else if ((hasfocus) && focus) {                     edittext.setbackgroundresource(r.drawable.black);                     focus = false;                 }             }         });     } 

in case instead of onfocuschangelistener() can use onclicklistener() want change on each click, can :

int res = r.drawable.black; // default background  etemailadress.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             if (res == r.drawable.black) {                 res = r.drawable.btn_green;             } else {                 res = r.drawable.black;             }             etemailadress.setbackgroundresource(res);         }     }); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -