In my values.xml file, I have an array, like this;
- Cow<
String[] array = context.getResources().getStringArray(R.array.animals_array);
String randomStr = array[new Random().nextInt(array.length)];
Hope this helps.
String[] myArrayOfStrings = {"one", "two", "three" }
Random r = new Random();
String myRandString = r.nextInt(myArrayOfStrings.length );
1. Retrive the Complete String Array from the xml and put it inside an ArrayList using
Arrays.asList()
method.
2. Use Math.random()*mArr.size()
function to get a random number. (mArr is the ArrayList)
3. Then use this random number to get an animal from the ArrayList like
`myArr.get(myrand);`
4. The reason i suggested the use of ArrayList (ie Collection framework) cause that will give you more flexibility.