I have some problems. I am a beginner programmer. I need to create an application like a clock with Android Studio and need to add and subtract hours and minutes. When I press the +1H will need to add 1H to take the same with +1M and -1M and I can't coordinate how can I do that. I am doing so that when the clock reached 23:59 again, it was 00:00 and so cyclically
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Button button,button2,button3,button4;
private TextView textView;
int hour = 0;
int minute = 0;
int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
button2 = findViewById(R.id.button2);
button3 = findViewById(R.id.button3);
button4 = findViewById(R.id.button4);
textView = findViewById(R.id.res);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (hour >= 9) {
textView.setText((++hour + "") + ":" + "00");
} else {
textView.setText("0" + (++hour + "") + ":" + "00");
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(hour>=9) {
textView.setText((--hour + "") + ":" + "00");
}else{
textView.setText("0"+(--hour + "") + ":" + "00");
}
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(minute>=9) {
textView.setText("00" + ":" + (++minute + ""));
}else{
textView.setText("00" + ":" + "0"+(++minute + ""));
}
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(minute>=9) {
textView.setText("00" + ":" + (--minute + ""));
}else{
textView.setText("00" + ":" + "0"+(--minute + ""));
}
}
});
}
}