我想切换按钮关闭时,计时器完成
问题描述:
OnCheckChanged 我想检查器isChecked 定时启动,当它做我想将它转换为关闭和停止按钮我想切换按钮关闭时,计时器完成
if(isChecked){
//on
timer.start();
Client myClient= new Client(serverIP,serverPort,t1,"h");
myClient.execute();
String data=t1.getText().toString();
Toast.makeText(getContext(),data,Toast.LENGTH_LONG).show();
buttonView.setText("On irrigation");
Toast.makeText(getContext(), "Irrigation On" + getItem(position), Toast.LENGTH_SHORT).show();
if(time==0)
{
buttonView.setChecked(false);
myClient= new Client(serverIP,serverPort,t1,"g");
myClient.execute();
data=t1.getText().toString();
}
答
简单使用Countdown
计时器:
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
// Here whatever you want to process in the mean time.
mTextField.setText("seconds remaining: " + millisUntilFinished/1000);
}
public void onFinish() {
// Here you can set your button to off state.
}
}.start();