Permalink
Browse files

Set the Time

  • Loading branch information...
dragosholban committed Mar 10, 2018
1 parent d3f8a4c commit 7c5f9d67e40e04ddcb4b0612016db678b32185e4
@@ -2,12 +2,42 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
Date localDate = new Date();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SeekBar seekBar = findViewById(R.id.seekBar);
final TextView userTime = findViewById(R.id.userTime);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) {
userTime.setText((seekBar.getProgress() < 10 ? "0" + Integer.toString(seekBar.getProgress()) : Integer.toString(seekBar.getProgress())) + ":00");
localDate.setHours(seekBar.getProgress());
if (fromUser) {
localDate.setMinutes(0);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
seekBar.setProgress(localDate.getHours());
}
}
@@ -41,6 +41,7 @@
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:max="23"
app:layout_constraintBottom_toTopOf="@+id/dateButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"

0 comments on commit 7c5f9d6

Please sign in to comment.