dimanche 4 février 2018

getting the size of values.xml in android studio?

I'm doing a task in my android class, and in my values folder, I created a file called "values.xml" and in it I placed some random strings:

<string name="name1">John</string>
<string name="name2">Jane</string>
<string name="name3">Andre</string>

in my java file, I would like to get a random string, but I want this to be based on the size of the values.xml

Random random = new Random();
String randomString = getResources().getString(random.nextInt(3));
textView.setText(randomString);

this creates and fetches a random string, but instead of

random.nextInt(3);

I want it to fetch values.xml.size(); or something similar. Is there a smart way to do this? I've searched everywhere!




Aucun commentaire:

Enregistrer un commentaire