0

i have a List which contains a few Strings from the strings.xml.

A random number determines which text from the List will be shown. Then this text should be removed from the list.

Unfortunalely, the List.remove(index) ist not working for me.

What am I doing wrong?

strings.xml

<resources>
    <string name="app_name">ReadQuestions</string>
    <string-array name="questions">
        <item>Text 1</item>
        <item>Text 2</item>
        <item>Text 3</item>
        <item>Text 4</item>
        <item>Text 5</item>
    </string-array>
</resources>

MainActivity

public class MainActivity extends AppCompatActivity{

    List<String> questions;

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


questions = Arrays.asList(getResources().getStringArray(R.array.questions));
setNewText();
}

public void setNewText(){
        int rnd = new Random().nextInt(questions.size());
        textViewBehind.setText(questions.get(rnd));

        questions.remove(rnd);   // Not working
        Toast.makeText(this, "test", Toast.LENGTH_SHORT).show(); // Doesn't pop up somehow

    }

Has anybody an ideo why the remove method isn't working and why everything after that method isn't processed. It feels like there is some return statement in the remove method. Im new to Java, but even if the onCreate method is just called once, could it be possible the questions = Arrays.asList(getResources().getStringArray(R.array.questions)); is called every cycle and fills the List again?

Best regards

andyyy
  • 23
  • 3

0 Answers0