java – How to increment day of month once per second in TextView Android

Question:

Good evening. Please tell me how to write such a counter that increases the day of the month every second, independently immediately after creating the onCreate method.

private TextView timeDate;
java.util.Date noteTS = Calendar.getInstance().getTime();
String date = "dd MMMM yyyy"; // 01 January 2013
timeDate.setText(DateFormat.format(date, noteTS));

Answer:

The following code will execute the body of the run() method every second. In it, instead of the current time, as in the example, you can display the date in the format you need. You can also create a variable that you will increment every second, in your case, you can change the value of the month.

android.os.Handler handler = new android.os.Handler();
int i = 0;
TextView textView = new TextView(this);
int refreshTime = 1000; // 1 second
textView.post(new Runnable() {
    @Override
    public void run() {
        i++; //for example you can increment value there
        textView.setText((int) System.currentTimeMillis()+"");
        handler.postDelayed(this,refreshTime);
    }
});
Scroll to Top