android - Changing and setting button background color and also comparing clicks on button pressed using switch and case -
i have been working on examination app while now, please stock setting buttons background colors comparing values on every button pressed. below code, please getting wrong? gives me no error , don't satisfy desired task.
switch (v.getid()) { case r.id.option1: button s2 = (button) findviewbyid(r.id.option2); actual = boption1.gettext().tostring(); s2.getbackground().setcolorfilter(0xff33ff33, porterduff.mode.multiply); boption2.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption3.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption4.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); aoption1 = 1; aoption2 = 0; aoption3 = 0; aoption4 = 0; break; case r.id.option2: actual = boption2.gettext().tostring(); boption1.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption2.getbackground().setcolorfilter(0xff33ff33, porterduff.mode.multiply); boption3.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption4.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); aoption1 = 0; aoption2 = 1; aoption3 = 0; aoption4 = 0; break; case r.id.option3: actual = boption3.gettext().tostring(); boption1.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption2.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption3.getbackground().setcolorfilter(0xff33ff33, porterduff.mode.multiply); boption4.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); aoption1 = 0; aoption2 = 0; aoption3 = 1; aoption4 = 0; break; case r.id.option4: actual = boption4.gettext().tostring(); boption1.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption2.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption3.getbackground().setcolorfilter(0x33ff33ff, porterduff.mode.multiply); boption4.getbackground().setcolorfilter(0xff33ff33, porterduff.mode.multiply); aoption1 = 0; aoption2 = 0; aoption3 = 0; aoption4 = 1; break; case r.id.confirm: tvexplain.settext(explain); ahint.setvisibility(view.visible); proceed.setvisibility(view.visible); proceed.settext(continued); confirm.setvisibility(view.invisible); confirm.setlayoutparams(new layoutparams(3, 1)); if(actual.equals(null)){ }else{ if(actual.equals(answer)){ if(aoption1 == 1){ boption1.getbackground().setcolorfilter(0xff66ff66, porterduff.mode.multiply); }else if(aoption2 == 1){ boption2.getbackground().setcolorfilter(0xff66ff66, porterduff.mode.multiply); }else if(aoption3 == 1){ boption3.getbackground().setcolorfilter(0xff66ff66, porterduff.mode.multiply); }else if(aoption4 == 1){ boption4.getbackground().setcolorfilter(0xff66ff66, porterduff.mode.multiply); } } } break; }
why don't use android art studio create different colors buttons?
Comments
Post a Comment