I am puzzled with how to use Async. I am wanting it to update the UI as soon as a button is clicked without having to kill the activity and re instantiate it. In the background, I want it to be waiting for the click to update the UI, and after the click I want it to determine whether or not the correct button was clicked. I am using the boolean isUserRight(); to determine whether or not the answer is correct, and after that I am using resetButtons(); to reset the buttons (obviously) and then setButtons(); to change the button. I have the methods all written out, I just don't know how to implement them into Async. I need the UI to be updated instantly to change the color of a button. I don't need help with any of the methods, button color, etc, just the Async, and I'm not asking anybody to spoonfeed me either, just give me a little push on where to go. Any help would be nice, thanks guys!
TL;DR need to update UI after button is pushed using async so the button color doesn't get stuck and I don't have to restart the activity to update the UI. I don't need the whole code, just a little guidance on where to go.
Edit: Added some code.
This is on my onCreate();
buttons[0] = (Button)findViewById(R.id.b0);
buttons[1] = (Button)findViewById(R.id.b1);
buttons[2] = (Button)findViewById(R.id.b2);
buttons[3] = (Button)findViewById(R.id.b3);
buttons[0].setOnClickListener(this);
buttons[1].setOnClickListener(this);
buttons[2].setOnClickListener(this);
buttons[3].setOnClickListener(this);
then under my onClick, I have a switch for the buttons which all go to this method:
public boolean isUserRight() {
if(correct == 1) {
onButton();
return true;
//Toast.makeText(getApplicationContext(), "Good job!", Toast.LENGTH_SHORT).show();
//buttons[test].getBackground().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);
}
onButton();
return false;
}
public void onButton() {
int rnd = new Random().nextInt(buttons.length);
test = rnd;
buttons[rnd].getBackground().setColorFilter(Color.YELLOW, PorterDuff.Mode.MULTIPLY);
//ResetButtons();
}
And this works fine, the only problem is after the first button being clicked, the colors stop changing and getting updated.