How to start Chronometer using DialogFragment

  • Thread starter Thread starter Android Central Question
  • Start date 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();
}
}
 
I moved this to the Software Development forum for more specific traffic.
 

Latest posts

Trending Posts

Forum statistics

Threads
956,286
Messages
6,967,430
Members
3,163,505
Latest member
NirvaanGuilloux