问题
I have been searching here in this forum but I cannot find any answer to my question. I have the following problem:
I have a imageview and two texts, and I want to change the color on selection to show show visual feedback before loading the next activity.
@Override
public void onClick(View v) {
openFormOverviewButton.setColorFilter(0x22FFFFFF, Mode.SRC_ATOP);
openFormOverviewTitle.setTextColor(0xFF00851B);
openFormOverviewText.setTextColor(0xFF00851B);
Intent tki = new Intent();
tki.setClass(getApplication(), DataCollectorFormOverviewActivity.class);
startActivity(tki);
}
I would expect that the button and the texts are changed and then the new activity is started. However, the text does not change and the activity starts. If I invoke the three lines in a runnable on the UI thread (runOnUiThread(new Runnable() {...}) then the changes are applied before the activity is started. This is actually strange, because the onClick method is called on the main thread aka. UI thread.
Does that mean that changes to the UI thread are not executed imediatelly on the UI thread? Or am I doing something completely wrong?
Best, Adam
回答1:
Correct. Changes to UI elements are not executed immediately. They're executed the next time the UI loop runs, which is after you release control. This is why you can't do expensive operations on the UI thread.
来源:https://stackoverflow.com/questions/4717722/how-will-ui-changes-be-processed-in-the-onclicklistener-before-starting-a-new-ac