使用android app inventor显示计时器显示
我想写一个应用程序,倒计时60秒显示屏幕上的标签倒计时,60秒后显示图片 我无法定义时钟/计时器部分。使用android app inventor显示计时器显示,android,app-inventor,Android,App Inventor,我想写一个应用程序,倒计时60秒显示屏幕上的标签倒计时,60秒后显示图片 我无法定义时钟/计时器部分。 有人能帮我吗 您可以使用CountDownTimer类:如示例所示: public class Countdown extends Activity { private TextView txtStatus; private ImageView image; @Override public void onCreate(Bundle icicle) {
有人能帮我吗 您可以使用CountDownTimer类:如示例所示:
public class Countdown extends Activity {
private TextView txtStatus;
private ImageView image;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
public void onResume() {
super.onResume();
setContentView(R.layout.main);
this.txtStatus = (TextView) this.findViewById(R.id.tv);
this.image = (ImageView) this.findViewById(R.id.image);
new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
txtStatus.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
image.setVisibility(View.VISIBLE);
}
}.start();
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="60"
/>
<ImageView android:layout_height="wrap_content" android:visibility="gone"
android:src="@drawable/icon" android:layout_width="wrap_content" android:id="@+id/image"></ImageView>
</LinearLayout>
拥有variabledef块并将其设置为1。
让你的时钟间隔为1000 1秒
每次时钟触发计时器事件块时,将1添加到变量块集合中,设置为变量块值+1
然后在计时器事件中,检查变量的值是否为60。如果60显示图片并禁用计时器。
你能发布一些你尝试过的代码吗?