I have this array in which 12 elements are stored, I randomized the array and hope to select a random case, the only problem is that nothing is returned, and I don't know why, any help?
My array:
<array name="OneTimesTables">
<item>1 x 1 = </item>
<item>1 x 2 = </item>
<item>1 x 3 = </item>
<item>1 x 4 = </item>
<item>1 x 5 = </item>
<item>1 x 6 = </item>
<item>1 x 7 = </item>
<item>1 x 8 = </item>
<item>1 x 9 = </item>
<item>1 x 10 = </item>
<item>1 x 11 = </item>
<item>1 x 12 = </item>
</array>
My code to call the array:
CurrectQuestions = (TextView)findViewById(R.id.CurrentQuestion);
final TypedArray MathsArray = getResources().obtainTypedArray(R.array.OneTimesTables);
ArrayList<Integer> RandomNumbers = new ArrayList<>();
for (int i = 0; i < 12; i++){
RandomNumbers.add(i);
}
Collections.shuffle(RandomNumbers);
int i = 0;
final int Question = MathsArray.getResourceId(RandomNumbers.get(i++), -1);
Toast.makeText(getApplicationContext(), "Question " + Question, Toast.LENGTH_SHORT).show();
CurrectQuestions.setText(Question);
source
share