0
votes

I am fetching some data from my server using the retrofit api:

    Call<String> call = api.fetch_details("get details",emp.getText().toString());

    if (call != null) {
        call.enqueue(new Callback<String>() {
             @Override
             public void onResponse(Call<String> call, Response<String> response) {
                      if(response.body()!=null){
                             //display result here
                      }
             }
        }
    }

It takes some time for the data to be fetched and displayed, so in the mean time I want to play a loading gif as animation. How do I proceed?

1

1 Answers

0
votes

Please try this:

Call<String> call = api.fetch_details("get details", emp.getText().toString());
/*
 * Show your loading animation here.
 * For example:
 *
 * loadingAnimation.show();
 *
 * */
if (call != null) {
    call.enqueue(new Callback<String>() {
        @Override
        public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
            /*
             * Dismiss loading animation here
             *
             * loadingAnimation.dismiss();
             * */
            if (response.body() != null) {
                //display result here
            }
        }

        @Override
        public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
            /*
             * Dismiss loading animation here
             *
             * loadingAnimation.dismiss();
             * */
            t.printStackTrace();
        }
    });
}