Loading Indicator
Explore how to implement a visible loading indicator using ProgressBar in the Travel Blog app details screen. This lesson helps you improve user experience by showing progress feedback during network data loading, ensuring the interface remains clear and responsive.
We'll cover the following...
Loading data from the network can take time, especially with a weak internet connection. Currently, while data is loading, the user sees a blank screen, which may be confusing. That’s why we need to introduce some kind of loading indicator.
We can show a simple ProgressBar, similar to what we did on the login screen, in the middle of the screen while data is loading.
Let’s start by declaring ProgressBar in the activity_blog_details file and constrain it to the middle of the screen. Leave the ProgressBar visible by default.
Next, in the BlogDetailsActivity bind the ProgressBar view to the Java field.
Finally, in the showData method we can hide the ProgressBar.
Now, when we launch the application, we should see a loading indicator.
Hit the run button to try it yourself.
package com.travelblog.http;
public class Author {
private String name;
private String avatar;
public String getName() {
return name;
}
public String getAvatar() {
return avatar;
}
}
The next lesson will introduce how to handle and recover from errors.