android - How to randomly choose between two choices -


let's have choices , button randomly picks 1 of choises:

  • i android
  • i ios

how randomly pick answer using button?

you can in button's onclick() method:

random rand=new random()  int x = rand.nextint(2); if(x == 0)   //  choose answer 1 else //   choose answer 2 

you can use math library too:

int x = (math.random() < 0.5) ? 0:1; if(x == 0)   //  choose answer 1 else //   choose answer 2 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -