android - String Array increment each string in TextToSpeech -


using text speech api want change string array increment index 0 string , when reaches end go beginning.

at moment uses random generator , method works follows:

 public static void sayhello() {     // select random hello.      int hellolength = hellos.length;     string hello = hellos[random.nextint(hellolength)];     mtts.speak(hello,         texttospeech.queue_flush,  // drop pending entries in playback queue.         null); } 

hellos array , holds strings:

 string [] hellos = {"one" "two" "three" "four"}; 

appreciate thanks.

when want increment index loop around 0 again modulo friend.

int currenthelloindex = 0; public static void sayhello() {     // select random hello.      int hellolength = hellos.length;     string hello = hellos[currenthelloindex];     currenthelloindex = (currenthelloindex + 1) % hellolength;     mtts.speak(hello,         texttospeech.queue_flush,  // drop pending entries in playback queue.         null); } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -