When my app is installed I want to see a progress bar until the image is loaded by an API call. After that, I want to make it invisible.
Here is the code:
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
// ...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=findViewById(R.id.imageView);
loud();
}
private void loud(){
setProgressBarVisibility(true);
RequestQueue queue = Volley.newRequestQueue(this);
String url ="https://meme-api.herokuapp.com/gimme";
// Request a string response from the provided URL.
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
String url= null;
try {
url = response.getString("url");
} catch (JSONException e) {
e.printStackTrace();
}
setProgressBarVisibility(false);
Glide.with(MainActivity.this).load(url).into(imageView);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("ERROR ","Error ");
}
});
queue.add(jsonObjectRequest);
}