private Button.OnClickListener listener = new Button.OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnBusl:
busl++;
txtBusl.setText("大型車" + busl + "輛");
break;
case R.id.btnBusc:
busc++;
txtBusc.setText("大型車" + busc + "輛");
break;
case R.id.btnBusr:
busr++;
txtBusr.setText("大型車" + busr + "輛");
break;
case R.id.btnCarl:
carl++;
txtCarl.setText("小型車" + carl + "輛");
case R.id.btnCarc:
carc++;
txtCarc.setText("小型車" + carc + "輛");
break;
case R.id.btnCarr:
carr++;
txtCarr.setText("小型車" + carr + "輛");
break;
case R.id.btnStl:
stl++;
txtStl.setText("機車" + stl + "輛");
break;
case R.id.btnStc:
stc++;
txtStc.setText("機車" + stc + "輛");
break;
case R.id.btnStr:
str++;
txtStr.setText("機車" + str + "輛");
break;
case R.id.btnZero:
busl = 0;
busc = 0;
busr = 0;
carl = 0;
carc = 0;
carr = 0;
stl = 0;
stc = 0;
str = 0;
txtStl.setText("機車0輛");
txtStc.setText("機車0輛");
txtStr.setText("機車0輛");
txtCarr.setText("小型車0輛");
txtCarl.setText("小型車0輛");
txtCarc.setText("小型車0輛");
txtBusr.setText("大型車0輛");
txtBusl.setText("大型車0輛");
txtBusc.setText("大型車0輛");
break;
}
}
};
public TimerTask tTask = new TimerTask() {
public void run() {
// 每秒要執行的程式
if (flagstrat == true) {
Message message = new Message();
if (s < 60) {
s++;
message.what = 1;
} else {
s = 0;
m++;
message.what = 2;
}
handler.sendMessage(message);
}
}
};
public Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
if (s < 10) {
sec.setText("0" + String.valueOf(s));// 秒數小於10補個零
} else {
sec.setText(String.valueOf(s));// 用textview顯示秒數
}
break;
case 2:
if (m < 10) {
min.setText("0" + String.valueOf(m));// 分數小於10補個零
} else {
min.setText(String.valueOf(m));// 用textview顯示分數
}
break;
default:
}
}
};
private Button.OnClickListener MyListener = new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.start:
flagstrat = true;
break;
case R.id.stop:
flagstrat = false;
break;
case R.id.reset:
m = 0;
s = 0;
min.setText("00");
sec.setText("00");
break;
}
}
};
@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);
}