I am making an app which is going to be always open into my tablet. I am trying to show the current date and time in real time. For the time, I use below code
<DigitalClock
android:id="@+id/digitalClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@+id/date"
tools:layout_editor_absoluteX="0dp" />
And it works perfectly. The app is always open and the time change in real-time (although I am searching now how to add the seconds).
For the date, I used that code
dateTimeDisplay = (TextView)findViewById(R.id.date);
calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE, dd MMMM, yyyy");
date = dateFormat.format(calendar.getInstance().getTime());
dateTimeDisplay.setText(date);
But it shows the current date, not in real-time. It changes only when I open the app.
I can tell because I put seconds in dateFormat to test it and it was static.
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE, dd MMMM, yyyy , ss");
Have anyone any idea?? Thank you!!