如何将用户界面的变化可以在onClickListener开始在Android的一个新活动前处理? [英] How will UI changes be processed in the onClickListener before starting a new activity in Android?

查看:238
本文介绍了如何将用户界面的变化可以在onClickListener开始在Android的一个新活动前处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找在这里在这个论坛上,但我找不到任何回答我的问题。我有以下问题:

I have been searching here in this forum but I cannot find any answer to my question. I have the following problem:

我有一个ImageView的和两个文本,我想改变颜色上选择加载下一个活动之前,以显示节目的视觉反馈。

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);
}

我期望的按钮和文本,然后再新的活动开始。但是,文本不会改变,活动开始。如果我调用三线处于可运行在UI线程(runOnUiThread(新的Runnable(){...}),然后在活动开始之前应用更改,这实际上是奇怪,因为onClick的方法被调用的主线程亦称UI线程。

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.

这是否意味着,到UI线程所做的更改不会在UI线程上执行imediatelly?还是我做的事情完全错了?

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

推荐答案

正确的。更改UI元素不立即执行。他们执行的UI循环下一次运行时,它就是你释放控制之后。这就是为什么你不能这样做在UI线程上昂贵的操作。

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.

这篇关于如何将用户界面的变化可以在onClickListener开始在Android的一个新活动前处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆