1
public void allButtonChoice(){
Button[] multiChoice = new Button[3];
multiChoice = new Button[]{choiceButton1,choiceButton2,choiceButton3,choiceButton4};

//to output shuffled array in an randomized order.
//Random number generator.

Random generateMultiChoice = new Random();

for(int i = 0; i < multiChoice.length; i++){
    int randomPosition = generateMultiChoice.nextInt(multiChoice.length);
    Button temp = multiChoice[i];
    multiChoice[i] = multiChoice[randomPosition];
    multiChoice[randomPosition] = temp;
}

//set the positions to the buttons in order
choiceButton1.setX(10f);
choiceButton1.setY(10f);
choiceButton2.setX(10f);
choiceButton2.setY(10f);
choiceButton3.setX(10f);
choiceButton3.setY(12f);
choiceButton4.setX(10f);
choiceButton4.setY(12f);
}

How can I assign a variable to choiceButton1, choiceButton2, choiceButton3, and choiceButton4? Is it possible to have one variable that holds the four buttons with setX and setY data?

1 Answer 1

1

choiceButton1.setTag(value);

will be useful for you

you can retrieve data by calling getTag

Sign up to request clarification or add additional context in comments.

1 Comment

can I retrieve x and y values? like this choiceButton1.setX(10f); choiceButton1.setY(10f); .... choiceButton1.setTag(choiceButton1); thank you for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.