我想制作一个计时器,它将显示在我的应用程序的每个活动中。
我知道如何在下面的活动上制作计时器是我的代码
public class Timer extends Activity implements OnClickListener {
public TextView mTextField;
private Button btnstart;
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
btnstart = (Button)findViewById(R.id.btnThread1);
btnstart.setOnClickListener(this);
//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.txtThread1);
final TextView mCounter2TextField = (TextView)findViewById(R.id.txtThread2);
//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();
}
};
}
@Override
public void onClick(View v) {
if(v == btnstart)
{
Counter1.start();
}
}
}
我想知道如何让它全球化??