1
I’m developing an app and it uses the timer by clicking on play to start and pause it to pause, only when I click again on play he Zera, would have how to keep counting the time?
java code:
public class FutebolSimples extends AppCompatActivity {
private ImageButton imgButton_play, imgButton_pause, imgButton_1, imgButton_2;
private TextView txt_valor1, txt_valor2;
private int contador = 0;
private int contador1 = 0;
private Chronometer reloginho;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_futebol_simples);
imgButton_1 = (ImageButton) findViewById(R.id.imgButton_1);
imgButton_2 = (ImageButton) findViewById(R.id.imgButton_2);
imgButton_play = (ImageButton) findViewById(R.id.imgButton_play);
imgButton_pause = (ImageButton) findViewById(R.id.imgButton_pause);
reloginho = (Chronometer) findViewById(R.id.chronometer);
txt_valor1 = (TextView) findViewById(R.id.txt_valor1);
txt_valor2 = (TextView) findViewById(R.id.txt_valor2);
imgButton_play.setEnabled(true);
imgButton_pause.setEnabled(false);
imgButton_1.setEnabled(false);
imgButton_2.setEnabled(false);
imgButton_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imgButton_play.setEnabled(false);
imgButton_pause.setEnabled(true);
imgButton_1.setEnabled(true);
imgButton_2.setEnabled(true);
reloginho.setBase(SystemClock.elapsedRealtime());
reloginho.start();
}
});
imgButton_pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imgButton_play.setEnabled(true);
imgButton_pause.setEnabled(false);
imgButton_1.setEnabled(false);
imgButton_2.setEnabled(false);
reloginho.stop();
}
});
}
}
Thank you.
Do you want to continue counting from the value you were when you stopped or should you consider the time you spent until you continue?
– ramaral