0

I have an array list which have multiple values. I am performing Random function on array list and I want to store each random value which occurs lets say on a click of a button in list view. How can I do that?

Int rand;
String[] listv={"one","two","three","four","five"}
rand=(int)(Math.random()*5);
ArrayList<String> planetList = new ArrayList<String>();  planetList.addAll(Arrays.asList(listv[rand]));
adapter = new ArrayAdapter<String>(this, R.layout.txtlay,planetList);
listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
ilse2005
  • 11,189
  • 5
  • 51
  • 75
n.sharma
  • 1
  • 3

1 Answers1

0

Use two different lists: The first one contains all possible values, the second one contains all randomly added values for the list view.

  1. Create an empty List rndValues
  2. Create your adapter with that empty list
  3. Set the adapter to your listView
  4. On your event (for example the button_click) add a random value of your listv to rndValues
  5. Call notifyDataSetChanged() on your adapter to update your list view
selmaohneh
  • 553
  • 2
  • 17