title: How can I use CountdownTimer on a fragment?
body: <p>I'm new to android studio and I'm trying to make a timer within a fragment. I want an app that starts a timer when I clicked a button.</p>
  
  <p>this is my fragment code</p>
  
  <pre><code>public class tab3Fragment extends Fragment {
      private static final String TAG = "tab3Fragment";
  
      CountDownTimer countDownTimer= new CounterClass(180000, 1000);
      private Button btn3;
      private TextView timer;
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.tab3_fragment,container,false);
          timer= (TextView) view.findViewById(R.id.timer);
  btn3= (Button) view.findViewById(R.id.startBTN);
  
          btn3.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  countDownTimer.start();
              }
          });
          return view;
  
      }
  
      public  class CounterClass extends CountDownTimer{
          @Override
          public void onTick(long millisUntilFinished) {
              long millis= millisUntilFinished;
              String hms= String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
                      TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
                      TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
              );
              timer.setText(hms);
          }
      }
  
  }
  </code></pre>
  
  <p>i don't know if I'm right.</p>