java - case staement switch with an intent -


i wondering if there way better. how can change compare integers instead or there easier way don't have lot of if statements or should try using enum compare strings?

public void onclick(view v)  {     intent choiceintent = getintent();     string msg = choiceintent.getstringextra("choice1");      if (msg.contentequals("option1"))     {                    if (v.getid() == r.id.button1)         {                        intent intent1 = new intent(this,choice3.class);              intent1.putextra("choice2", "option3");             startactivityforresult(intent1, 1);              this.startactivity(intent1);             }         else if (v.getid() == r.id.button2)         {                    intent intent1 = new intent(this,choice3.class);              intent1.putextra("choice2", "option4");             startactivityforresult(intent1, 1);              this.startactivity(intent1);             }        }     else if (msg.contentequals("option2"))     {          if (v.getid() == r.id.button1)         {                     intent intent1 = new intent(this,choice3.class);              intent1.putextra("choice2", "option5");             startactivityforresult(intent1, 1);              this.startactivity(intent1);                 }          else if (v.getid() == r.id.button2)         {             intent intent1 = new intent(this,choice3.class);              intent1.putextra("choice2", "option6");             startactivityforresult(intent1, 1);              this.startactivity(intent1);         }        } } 

use enums.

intent1.putextra("choice1", yourenum.option_3); 

and retrieve value, use

choiceintent.getserializableextra("choice1"); 

that allow use enum switch statement.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -