安装我的应用程序后,我希望看到一个进度条,直到通过 API 调用加载图像。在那之后,我想让它不可见。
这是代码:
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);
}