Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove from arraylist
    text
    copied!<pre><code>My code is this: public class startgame extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.level1); final Random rgenerator = new Random(); //setup the questions List&lt;String&gt; questions1 = new ArrayList&lt;String&gt;(); questions1.add("Who is the actual CEO at Apple?"); questions1.add("Who is the actual CEO at Microsoft?"); questions1.add("Android is made by:"); String thequestion = questions1.get(rgenerator.nextInt(questions1.size())); TextView question = (TextView)findViewById(R.id.textView1); question.setText(thequestion); questions1.remove(thequestion); //Initialise the button variables Button button1 = (Button)findViewById(R.id.button1); Button button2 = (Button)findViewById(R.id.button2); Button button3 = (Button)findViewById(R.id.button3); Button button4 = (Button)findViewById(R.id.button4); if (thequestion.equals("Who is the actual CEO at Apple?")) { List&lt;String&gt; questions1res = new ArrayList&lt;String&gt;(); questions1res.add("Steve Jobs"); questions1res.add("Steven Sinofsky"); questions1res.add("Tim Cook"); questions1res.add("Steve Ballmer"); button1.setText(questions1res.get(rgenerator.nextInt(questions1res.size()))); questions1res.remove(button1.getText()); button2.setText(questions1res.get(rgenerator.nextInt(questions1res.size()))); questions1res.remove(button2.getText()); button3.setText(questions1res.get(rgenerator.nextInt(questions1res.size()))); questions1res.remove(button3.getText()); button4.setText(questions1res.get(rgenerator.nextInt(questions1res.size()))); questions1res.remove(button4.getText()); } } public void onClick(View v) { switch (v.getId()){ case R.id.button1: case R.id.button2: case R.id.button3: case R.id.button4: } } } </code></pre> <p>What id does is this: Choose 1 question from that arraylist of questions. Create the buttons, and put the chosen question in a string, and show that string on the screen. If that string is 'Who is the actual CEO at Apple?' then randomly put Steve Jobs and all those answers on buttons.</p> <p>What I want is this: If the user presses the button that contains: 'Tim Cook' then: Remove 'Who is the actual CEO at Apple?' from the questions list, and randomly chose another question from the ArrayList of questions, and randomly put the answers on the buttons (the same stuff I already did, just that is another question).</p> <p>My problem is that I can't really have acces to the array to delete it,because all I got is the case when the button is pressed.I tried to make a function,but every time I execute the function,the list is always recreated....</p> <p>Can someone correct the code for me? And add what is missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload