How to start Chronometer using DialogFragment

  • Thread starter Android Central Question
  • Start date
A

Android Central Question

How to start a Chronometer when a DialogFragment is clicked (its OK button)? I have something like the following, but it gives null object reference error. I want the timer to start only after the user clicks the ok button in the dialogFragment.
Code:
public class A extends AppCompatActivity {
private Chronometer mChronometer;
 [MENTION=93274]overr[/MENTION]ide
   protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
       setContentView(R.layout.activity);
       mChronometer = findViewById(R.id.chronometer);
       mChronometer.setBase(SystemClock.elapsedRealtime());
}
public void startTimer(){
  // This method is start using Fragment.
   mChronometer.start();
}
}
 

Forum statistics

Threads
943,398
Messages
6,918,689
Members
3,158,992
Latest member
ab07