Using Volley to request an image
Once you make your JSON Requests as demonstrated in the previous recipe, the next most likely call you'll be making is to get an image. This recipe will demonstrate how to request an image to update an ImageView
.
Getting ready
Create a new project in Android Studio and call it ImageRequest
. Use the default Phone & Tablet option and select Empty Activity when prompted for Activity Type.
This recipe will be using the setup described in the Getting started with Volley for Internet requests recipe. Follow steps 1-5 to add Volley to your new project.
How to do it...
With Volley added to your project, as described previously, follow these steps:
- Open
activity_main.xml
and replace the existingTextView
with the following XML:<ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <Button android...