I need to start the countdown timer in this activity. It should be started from the button. Below I bring the code snippets.
I think I did everything right, but it doesn't work - why is this?
public class Step5 extends AppCompatActivity {
Button mgo;
public TextView timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.step5);
timer = (TextView) findViewById(R.id.timer);
mgo = (Button) findViewById(R.id.go);
mgo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new CountDownTimer(900000,1000) {
@Override
public void onTick(long millisUntilFinished) {
timer.setText((int)millisUntilFinished/1000);
}
@Override
public void onFinish() {
timer.setText("Done");
}
}.start();
}
});
}}
Button in xml
<Button
android:id="@+id/go"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#FF3D00"
android:textColor="#ffffff"
android:text="@string/Start"
android:layout_alignParentBottom="true"/>