How to set text by date and increment loop android?

I want to set text by date and incrementing loop, and when the day changes looping start from the beginning.

Example

1. day 1 =
   a. nameFile 110920190001
   b. nameFile 110920190002, etc.

2. day 2 =
   a. nameFile 120920190001
   b. nameFile 120920190002, etc.

Code

Date documentsDate = Calendar.getInstance().getTime();
SimpleDateFormat documentDates = new SimpleDateFormat("ddMMyy");
String setTitleDocument = documentDates.format(documentsDate);       

for(int i = 1; i <= 1000; i++) {
    String countDocument = String.format("%04d", i);
    textNameDocument.setText("Document " + setTitleDocument + countDocument);
}

Upvotes: 0

Views: 254

Answers (1)

kunal manocha
kunal manocha

Reputation: 118

Just put the Date Initialization in the for loop for it to always take the new Instance of the date.

public static void replace(String s) {
    for (int i = 1; i <= 1000; i++) {
        Date documentsDate = Calendar.getInstance().getTime();
        SimpleDateFormat documentDates = new SimpleDateFormat("ddMMyy");
        String setTitleDocument = documentDates.format(documentsDate);
        String countDocument = String.format("%04d", i);
        textNameDocument.setText("Document " + setTitleDocument + countDocument);
    }
}

Upvotes: 1

Related Questions