我正在实现倒数计时器,但它对我不起作用。下面是代码。
package FinalProj.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.os.CountDownTimer;
public class iFallApp extends Activity{
public TextView textView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TextView textview = new TextView(this);
//textview.setText("This is the iFall tab");
// setContentView()
setContentView(R.layout.ifallapp);
textView1=(TextView) findViewById(R.id.textView1);
MyCount counter = new MyCount(5000,1000);
counter.start();
}
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
iFallApp app1 = new iFallApp();
@Override
public void onFinish() {
// TODO Auto-generated method stub
textView1.setText("done");
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
textView1.setText((int) (millisUntilFinished/1000));
}
}
}
最佳答案
正是这条线导致了问题;
textView1.setText((int) (millisUntilFinished/1000));
你所做的是为 textView1 设置一个资源 id,而你正在寻找的是类似的东西;
textView1.setText(Long.toString(millisUntilFinished/1000));
也行;
iFallApp app1 = new iFallApp();
比较可疑。以防万一,在您最终不小心使用它之前将其删除。您已经拥有由 Android 框架创建的 iFallApp,如果需要,您可以使用
this
来传递它。