gpt4 book ai didi

Android使计数器下降?

转载 作者:行者123 更新时间:2023-11-29 18:17:31 24 4
gpt4 key购买 nike

我是一个初学者 ..当我的程序开始时我想做一个计数器下降 .. :5个4个3个2个1个开始做事

简单

谢谢

最佳答案

我认为这会给你一个很好的起点......

package com.example.countdown;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class CountdownDemoActivity extends Activity {
private TextView number;
private int countdownNumber = 5;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

number = (TextView) findViewById(R.id.number);

TimerTask countdownTask = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(countdownNumber == 0) {
cancel();
}
number.setText(String.valueOf(countdownNumber));
countdownNumber--;
}
});
}
};

Timer countdown = new Timer();
countdown.schedule(countdownTask, 0, 1000);
}
}

关于Android使计数器下降?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7314513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com