App Inventor - 逻辑

时间:2016-12-11 20:16:51

标签: android app-inventor

这个非常简单的代码不会按照它应该的方式运行,我不太明白为什么。

App Inventor代码:

When Button1.Click
#1  set Label1.Text to "Wait"
#2  call ProcedureXYZ
#3  set Label1.Text to "Done"

这是问题所在。 ProcedureXYZ需要5秒钟才能完成。所以Label1应该显示“等待”,但事实并非如此。相反,第1行,第2行,第3行同时执行。换句话说,它会消失5秒钟,然后显示“完成”(这是因为它会立即覆盖“等待”)。

因此,对于5秒钟,我的应用似乎被冻结,直到ProcedureXYZ完成其计算。我的问题是,ProcedureXYZ需要5秒才能完成时,如何显示“等待”?

我尝试使用时钟来启动“等待”消息,但这也不起作用。唯一有效的方法是显示警报消息,但我不想要弹出消息。

1 个答案:

答案 0 :(得分:0)

为什么 App Inventor 中的此功能不起作用,请在此处解释:由Lyn The model of event processing in App Inventor

您必须使用Clock组件才能执行此操作,请参阅下面的伪代码。在Designer中,设置一个非常小的TimerInterval(例如10毫秒)并将属性TimerEnabled设置为false。

Button1.Click事件

set Label1.Text to "Wait"
set Clock.TimerEnabled to true

Clock.Timer事件

set Clock.TimerEnabled to false  
call ProcedureXYZ
set Label1.Text to "Done"