1

I'm currently searching how to update my progress bar which is located in my dialog window. I have already multiple post on this but I can't understand why my progress bar won't update.

Here is my code :

public class Dataset1Fragment extends Fragment {
private static final int APP_SMS_DEFAULT = 5;
DatabaseHelper myDb;
ProgressBar progressBar;
Dialog dialog;

private Button btnInsert;
private Button btnDelete;
String[] pictures = null;
private RelativeLayout lay_dataset1;

@SuppressLint("InflateParams")
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.progress, null);
    progressBar = view.findViewById(R.id.loader);
    return inflater.inflate(R.layout.fragment_dataset1, null);
  }
}

This is the part of fragment where I just called the progressBar

And this part is my AsyncTask :

 // ASYNC TASK POUR DELETE
private class ExampleAsyncTaskDelete extends AsyncTask<Integer, Integer, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        setDialog(true);
        progressBar.setMax(100);
        Log.d("DELETE THREAD", "PreExecute");
    }

    @Override
    protected String doInBackground(Integer... integers) {

        for (int i=0; i<100;i++){
            publishProgress(i);
            try {
                Thread.sleep(100);
            }catch (InterruptedException ie){
                ie.printStackTrace();
            }
        }
        return "Finished!";
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        progressBar.setProgress(values[0]);
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Toast.makeText(requireContext(), "Delete ok", Toast.LENGTH_SHORT).show();
        setDialog(false);
        requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
    }
}

public void setDialog(boolean show) {
    if (show) dialog.show();
    else dialog.dismiss();
}

The those part are in the same file. It is not impossible to have a progress bar in a "dialog" right ? I missed sth for sure but what?

Louis Chabert
  • 399
  • 2
  • 15

0 Answers0