Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging UI in an OnclickListener that attaches to an AsyncTask
    primarykey
    data
    text
    <p>I have an OnClickListener that from what I understand should run a method called changeTitleToYellow, which changes a textview to a yellow background and changes the text.</p> <p>My onClickListener looks like the following:</p> <pre><code> relayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { changeTitleToYellow(); System.out.println(tvSocketConnection.getText().toString()); if (relayStatusArray[relayNumber] == 0) { if (cPanel.TurnOnRelay(relayNumber, 1) == false) { changeTitleToRed(); }else{ changeTitleToGreen(); } } else { if (cPanel.TurnOffRelay(relayNumber, 1) == false){ changeTitleToRed(); }else{ changeTitleToGreen(); } } relayStatusArray = cPanel.getBankStatus(1); updateButtonText(); } }); </code></pre> <p>The changeTitleToYellow method does get triggered and completes and it continues on down to the if statements which trigger methods in another class with an AsyncTask in it. However the title never turns to yellow. The code runs, but the UI changes don't come into effect until after the AsyncTask completes.</p> <p>I checked and the changeTitleToYellow method runs on the UI thread so its not that.</p> <p>I'm pretty sure its just the way android operates, but does anyone know why it will run the code but not change the UI?</p> <p><em>edit</em></p> <p>Here is the changeTitleToYellowMethod:</p> <pre><code>public void changeTitleToYellow(){ System.out.println("In Change Title Yellow Method"); tvSocketConnection.setBackgroundColor(Color.YELLOW); tvSocketConnection.setText("NCD TCP Relay: Connecting...."); System.out.println("Endof Yellow"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload