0
我在eclipse中爲android製作秒錶。我正在使用天文鐘,我想知道如何顯示毫秒。這是我的代碼的樣子。 P.S:我是一個初學者,所以這可能聽起來愚蠢到你:P在天文臺顯示毫秒
Button startChrono;
Button pauseChrono;
Chronometer chrono;
long time = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startChrono = (Button) findViewById(R.id.button1);
pauseChrono = (Button) findViewById(R.id.button2);
chrono = (Chronometer) findViewById(R.id.chronometer1);
startChrono.setOnClickListener(this);
pauseChrono.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.button1:
chrono.setBase(SystemClock.elapsedRealtime() + time);
chrono.start();
break;
case R.id.button2:
time = chrono.getBase() - SystemClock.elapsedRealtime();
chrono.stop();
break;
}
}