dIvYaNsH sInGh
dIvYaNsH sInGh

Reputation: 1993

Progress Dialog with For Loop

How can I use Progress Dialog box with for Loop.

Means either inside the loop or outside the loop wherever it's possible. Currently I'm trying to use loop inside the progress dialog with it's not working.

for (int i = 0; i < 4; i++) {
    param = filename + "|" + String.valueOf(Outlet) + "|" + String.valueOf(UserId) + "|" + remarks + "|" + String.valueOf(rowid) + "|" + String.valueOf(ReportId);
    final String params = param;
    try {
        result = connectFTP();
        if (!result) {
            dbase.DeleteAlbum(rowid);
            Toast.makeText(this, "Record not uploaded.. Try Again..", Toast.LENGTH_LONG).show();
            handler.sendEmptyMessage(0);
            return;
        }
        if (result) {
            result = wcf.InsertAlbum(params);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 0

Views: 1224

Answers (1)

hackbod
hackbod

Reputation: 91341

You can't. For the progress dialog to display, your main thread needs to be running its message loop. The way you do work is to use AsyncTask or another facility to do that loop on a different thread.

Upvotes: 3

Related Questions