2016-05-23 25 views
0

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(); 

         } 

回答

1

簡單使用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();