ねえ、私は最近Androidにアクセスして、ユーザーがスタートボタンを押したときに60秒のランダウンタイマーを開始することを目的とした最初のアプリを作成しました。アプリケーションはコンテンツビューを正しく設定し、60を表示しますが、スタートボタンをクリックすると、59が正常に表示され、アプリがクラッシュします。コードは次のとおりです(アクティビティは1つだけです)。
public class test1activity extends Activity
{
Thread countdown;
long f, pa, jee;
TextView ytvp;
String s;
TextView uyti;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ytvp = (TextView) findViewById(R.id.textView2);
uyti = (TextView) findViewById(R.id.tv2);
countdown = new Thread() {
public void run() {
jee = (System.currentTimeMillis()) / 1000;
while ((((System.currentTimeMillis()) / 1000) - jee) < 60)
{
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
f = ((System.currentTimeMillis()) / 1000) - jee;
pa = 60 - f;
s = String.valueOf(pa);
ytvp.setText(s);
}
}
}
};
}
public void whenclickstart(View view) {
countdown.start();
}