Currently I have a counter that is subtracted every second, how can I add more time to the freetime variable when I click on the add time button?
if I add the variables before clicking the start button it works, but once the counter is active it does not add more time to the counter
TextView count_txt;
Button start_button,moretime_button;
int freetime = 1800000;
String time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.count_layout);
CountActivity.this.setTitle("CountDown");
//find view
start_button = findViewById(R.id.startcount_button);
count_txt = findViewById(R.id.textView_count);
moretime_button = findViewById(R.id.button_moretime);
moretime_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//add button
}
});
start_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new CountDownTimer(netTime,1000) {
@Override
public void onTick(long millisUntilFinished) {
time = String.format(Locale.getDefault(),"Time Remaining" "\n" "d:d:d",
TimeUnit.MILLISECONDS.toHours(millisUntilFinished)`,
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)% 60,
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished)% 60);
count_txt.setText((time));
netTime--;
}
@Override
public void onFinish() {
count_txt.setText("FINISH!!!");
}
}.start();
}
});
CodePudding user response: