I've done quite a few searches on this but can only find implementations that don't apply (e.g. using random, which I already have). Pretty rookie question, any help is greatly appreciated.
I got a string array and currently I return a random one through a simple function I implemented as the onCLick value of a button, code below. So, every time someone clicks on the bottun, a new string is set.
What I want to do instead is to go through the array top to bottom, returning one string at a time, and then start over. I suspect there might be several ways to do this, any suggestions? Thanks a lot in advance!
public class FirstActivity extends Activity {
private TextView myStringView;
private static final Random RANDOM = new Random();
String myString;
//....my other code
private static final String[] MYSTRINGS = {
"string a",
"string b",
"string c"
};
public void generateString(View v) {
int myStringsLength = MYSTRINGS.length;
String myString = MYSTRINGS[RANDOM.nextInt(myStringsLength)];
myStringView.setText(myString);
}
}