If you want to use the solution you describe in your question, you can achieve it pretty easily with an ArrayList
. This is assuming you have some sort of class for your buttons. If not, it might be a bit more cumbersome. The logic's the same though.
Create the initial list at the start of your class with the buttons:
ArrayList<Button> buttons = new ArrayList<Button>();
buttons.add(new Button("button1", xPos, yPos));
buttons.add(new Button("button2", xPos, yPos));
buttons.add(new Button("button3", xPos, yPos));
buttons.add(new Button("button4", xPos, yPos));
Then whenever the user clicks on one of them, run this:
// Make this equal the button the user clicks!
Button userSelection = GetClickedButton();
// Remove that button from the array.
buttons.remove(userSelection);
// Select a random button from the remaining ones.
Button toSwap = buttons.get(new Random().nextInt(buttons.size())));
// Now swap. Just swap the positions of the chosen buttons.
SwapButtonPositions(userSelection, toSwap);
// Add the removed button back to the list.
buttons.add(userSelection);
EDIT: I misread your question. I thought you wanted any button to be swappable, not just one of them. The logic for doing that is the same as above. Just have some way to tag the swappable button (like giving it a name) and run the code whenever it's clicked, rather than when any button's clicked.