M
M
MdaUZH2016-08-23 08:50:51
Android
MdaUZH, 2016-08-23 08:50:51

How to randomly scatter labels on buttons?

Hello everyone, I ran into a problem again, I don’t know how to correctly scatter the labels on the buttons:
There are 4 buttons and data from the database (1 correct entry and 3 random ones)
How will it be correct to scatter them randomly?
while saving the id of the correct button?
I'm kind of confused about this...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
artemsee, 2016-08-23
@artemsee

In theory, the algorithm will be something like this:
1. You get four records from the database
2. You generate a random number from 1 to 4, take the button under this number and insert the correct answer into it, mark it as a button with the correct answer.
3. The remaining buttons that have not yet been filled in are filled in the loop with the remaining entries (incorrect).

V
Vladimir Yakushev, 2016-08-23
@VYakushev

Have two OnClickListeners: one for the correct answer, the other for the wrong one. We put OnClickListener on the right button for the correct answer, on the rest for the wrong one. As a result, no id needs to be stored. Well, I think it will not be difficult to randomly scatter the buttons: just randomly select the number \ id of the correct button, and assign the rest arbitrarily.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question