0

I have a progressDialog in my fragment. The thing I need is to show little circle. But it is showing only message. It's killing me

final ProgressDialog progressDialog = new ProgressDialog(getActivity());
        progressDialog.setIndeterminate(true);
        progressDialog.setMessage("My message");
        progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Large);
        progressDialog.show();

Fragment - method show progress dialog is edited by your help

private void loginEmail() {

        showProgressDialog();
        FactoryAPI.getInstanceLogin().login("test@test.cz", "heslo123").enqueue(new Callback<UserResponse>() {
            @Override
            public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {
                if (response.isSuccessful()) {
                    user = response.body().getUser();
                    startActivity();
                    progressDialog.dismiss();
                } else {
                    Toast.makeText(getContext(), R.string.email_password_is_not_right, Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onFailure(Call<UserResponse> call, Throwable t) {
                Log.e("error", "error");
            }
        });
    }
Stepan
  • 1,041
  • 5
  • 23
  • 35

3 Answers3

1

Use a ProgressBar, not a ProgressDialog.
Example: Put this in your layout file where you want to put the ProgressBar:

<ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_gravity="center"
        style="@style/Base.Widget.AppCompat.ProgressBar" />

Then call progressBar.setVisiblity(view.visible) where you want to show it, and hide it when you finish loading what you want.

amitairos
  • 2,907
  • 11
  • 50
  • 84
1

Just remove

  progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Large);

By default the "loading" icon is the circle.

Hugo Houyez
  • 470
  • 3
  • 19
1

Simply change this line progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Large) to progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER)

private void loginEmail() {

    final ProgressDialog progressDialog = new ProgressDialog(getActivity);
    progressDialog.setIndeterminate(true);
    progressDialog.setMessage("My message");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.show();

    FactoryAPI.getInstanceLogin().login("test@test.cz", "heslo123").enqueue(new Callback<UserResponse>() {
        @Override
        public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {

            if(progressDialog.isShowing())
                 progressDialog.dismiss();

            if (response.isSuccessful()) {
                user = response.body().getUser();
                startActivity();
            } else {
                Toast.makeText(getContext(), R.string.email_password_is_not_right, Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onFailure(Call<UserResponse> call, Throwable t) {

            if(progressDialog.isShowing())
                 progressDialog.dismiss();

            Log.e("error", "error");
        }
    });
}

STYLE_SPINNER -

Creates a ProgressDialog with a circular, spinning progress bar.

STYLE_HORIZONTAL -

Creates a ProgressDialog with a horizontal progress bar.

Reference: ProgressDialog

Amad Yus
  • 2,856
  • 1
  • 24
  • 32