Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help fixing this app in Android Studio. The app is an countdown timer app. There are some errors/bugs. -The Up and Down buttons need

Need help fixing this app in Android Studio. The app is an countdown timer app. There are some errors/bugs.

-The Up and Down buttons need to be fixed, The Up increase the counter by 1 and Down decrease it by 1, the Textview should change accordingly.

-The start button and the stop button are also bugged, the start button seems to be doing nothing and the stop button seems to be doing what the start button should do, which is when you press the start button, the counter starts counting down, other than stop button all the other buttons are made invisible.

-If you press the stop button the counter stops, the reset and the start button are visible.

-If you press reset button all the buttons are visible and the counter resets to 30 Seconds.

////////////////////////////////////////////////////////////////////////////////Frontend Code Below///////////////////////////////////////////////////////

   

///////////////////////////////////////////////////////////////////////////////////////Java Backend Below/////////////////////////////////////////////////////////////////

package com.example.pavan.countdowntimer; import android.os.CountDownTimer; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.util.Locale; public class MainActivity extends AppCompatActivity { private static final long START_TIME_IN_MILLIS = 600000; private TextView tv_time; private Button btn_start; private Button btn_stop; private Button btn_reset; private CountDownTimer mCountDownTimer; private boolean mTimerRunning; private long mTimeLeftInMillis = START_TIME_IN_MILLIS; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv_time = findViewById(R.id.tv_count); btn_start= findViewById(R.id.btn_start); btn_reset = findViewById(R.id.btn_reset); btn_stop=findViewById(R.id.btn_stop); btn_stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mTimerRunning) { stopTimer(); } else { startTimer(); } } }); btn_reset.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { resetTimer(); } }); updateCountDownText(); } private void startTimer() { mCountDownTimer = new CountDownTimer(mTimeLeftInMillis, 1000) { @Override public void onTick(long millisUntilFinished) { mTimeLeftInMillis = millisUntilFinished; updateCountDownText(); } @Override public void onFinish() { mTimerRunning = false; btn_start.setText("Start"); btn_start.setVisibility(View.INVISIBLE); btn_reset.setVisibility(View.VISIBLE); } }.start(); mTimerRunning = true; btn_start.setText("stop"); btn_reset.setVisibility(View.INVISIBLE); } private void stopTimer() { mCountDownTimer.cancel(); mTimerRunning = false; btn_start.setText("Start"); btn_reset.setVisibility(View.VISIBLE); } private void resetTimer() { mTimeLeftInMillis = START_TIME_IN_MILLIS; updateCountDownText(); btn_reset.setVisibility(View.INVISIBLE); btn_start.setVisibility(View.VISIBLE); } private void updateCountDownText() { int minutes = (int) (mTimeLeftInMillis / 1000) / 60; int seconds = (int) (mTimeLeftInMillis / 1000) % 60; String timeLeftFormatted = String.format(Locale.getDefault(), "%02d:%02d", minutes, seconds); tv_time.setText(timeLeftFormatted); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago