我创建了一个计时器,它将通过编辑文本框接受用户指定的时间值并传递给 CountDownTimer()。这种方法需要一个长值,这就是为什么我将它转换为长但是当我添加这个长转换时,android 模拟器显示错误不幸停止了。这是我的代码
EditText ti=(EditText)findViewById(R.id.time);
Editable i = ti.getText();
String p=i.toString();
long x=Long.parseLong(p);
final TextView mCounter1TextField=(TextView)findViewById(R.id.counter1);
final CountDownTimer Counter1 = new CountDownTimer(x, 10) {
public void onTick(long millisUntilFinished) {
mCounter1TextField.setText(" " + (millisUntilFinished)/ 1000 + ":");
}
public void onFinish() {
mp3.start ();
Log.d ("Splash", "LauncherActivity.onCreate - created MediaPlayer");
cancel();
}
};
//Start Button1
btnstart.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Counter1.start();
}
};