I've read about collections to randomize the order of an object. With that, I'd like to try to randomize my buttons in my android application.
Here a chunk of code:
Button[] bObject = new Button[6];
private void getCorrectObject() {
// TODO getCorrectObject
List<Integer> objects = new ArrayList<Integer>();
objects.add(0);
objects.add(1);
objects.add(2);
objects.add(3);
objects.add(4);
// Shuffle the collection
Collections.shuffle(objects);
bObject[objects]; // I'm having trouble implementing the shuffle logic here.
}
SO any helpful response is truly appreciated. Thanks.
first
second:
or:
I think this is what you're looking for. Shuffling the elements in the
bObject
array.I had a same problem (shuffle buttons) and i come up with an easy solution I just used an array of integer numbers of buttons ids and simple shufle. In my case was that enough. It's simple and u get the same result.
I hope this will help. Regards !! (srry for my broken english)
got it solved manually and then tried to get it solved dynamically aswell. got a nice idea that you can do it with a second arraylist.
does this help you?
EDIT: yes let us solve this in chat. im also curious how this can be done!