mercredi 5 août 2015

Android Java If Int Color Change

I basically got hits:

int zander = 1;
if(zander == 1) {
    button01.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        public void onClick(View v) {
            ((Button) android.findViewById(R.id.one)).setBackground(getResources().getDrawable(R.drawable.border_inner_green));
            int zander =+ 1;
            System.out.println(zander+"green");

        }
    });
} else if(zander == 2){
    button01.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        public void onClick(View v) {
            ((Button) android.findViewById(R.id.two)).setBackground(getResources().getDrawable(R.drawable.border_inner_red));
            int zander =- 1;
            System.out.println(zander+"red");
        }
    });
}

So when I click at the button, the background color changes to green in drawable.border_inner_green. I tried to increase an integer value just to get so to say the second click of the user to make the background red afterwards. But somehow this won't work I keep getting green. Does anyone have one idea?

Aucun commentaire:

Enregistrer un commentaire