我正在尝试制作一个 android 应用程序,管理员将设置计时器倒计时,并且用户必须能够看到倒计时的时间......我可以设置计时器,但我不知道如何将其传递给另一个活动。 ..请帮助我的代码
public class Timer extends Activity {
public TextView mTextField;
public String formatTime(long millis) {
String output = "00:00";
long seconds = millis / 1000;
long minutes = seconds / 60;
seconds = seconds % 60;
minutes = minutes % 60;
String secondsD = String.valueOf(seconds);
String minutesD = String.valueOf(minutes);
if (seconds < 10)
secondsD = "0" + seconds;
if (minutes < 10)
minutesD = "0" + minutes;
output = minutesD + " : " + secondsD;
return output;
}
public CountDownTimer Counter1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Declare Start/Stop button
Button btnstart = (Button)findViewById(R.id.button01);
Button btnstop = (Button)findViewById(R.id.button02);
Button btnpass = (Button)findViewById(R.id.button03);
//Declare Text fields to show time left
final TextView mCounter1TextField=(TextView)findViewById(R.id.textView01);
final TextView mCounter2TextField = (TextView)findViewById(R.id.textView02);
final TextView mCounter3TextField=(TextView)findViewById(R.id.textView03);
//Counter 1
Counter1 = new CountDownTimer(120000 , 1000) {
public void onTick(long millisUntilFinished) {
mCounter1TextField.setText("Seconds left: " + formatTime(millisUntilFinished));
}
public void onFinish() {
mCounter1TextField.setText("Finished!");
// Counter1.start();
}
};
以及我需要接收计时器的活动
public class f extends Activity {
public TextView tt;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dfsdfsd);
Timer objtime = new Timer();
TextView productTitleTextView = (TextView) findViewById(R.id.textViewtimer);
productTitleTextView.setText("Left Time is : " + objtime.Counter1);
}
}