How to make TextView
with Drawable
on the left that(drawable) can be set programmaticaly from a url coming from the server.
Asked
Active
Viewed 788 times
2

earthw0rmjim
- 19,027
- 9
- 49
- 63

Rahul
- 189
- 1
- 13
-
You make a network request and update an ImageView. Please share what you have tried to research to implement this feature. – OneCricketeer Jun 11 '16 at 07:52
-
What is the problem? – Janki Gadhiya Jun 11 '16 at 07:52
-
Possible duplicate: https://stackoverflow.com/questions/8464506/how-to-display-an-image-from-an-url-within-textview – OneCricketeer Jun 11 '16 at 07:53
2 Answers
2
Well, the first step is to decode the image from the URL.
You could do something like this:
String yourUrl = "http://someUrl"; // insert your URL here
// connect, get an instance of the InputStream
HttpURLConnection connection = (HttpURLConnection) new URL(yourUrl).openConnection();
InputStream inputStream = connection.getInputStream();
// decode the stream into a Bitmap and create a Drawable from it
Bitmap tempBitmap = BitmapFactory.decodeStream(inputStream);
Drawable drawable = new BitmapDrawable(getResources(), tempBitmap);
And then, set it as a compound drawable on the left side of your TextView
:
// the order is left, top, right, bottom, so you need to set the first param
yourTextView.setCompoundDrawables(drawable, null, null, null);

earthw0rmjim
- 19,027
- 9
- 49
- 63
0
Use Volley Class to load images https://developer.android.com/training/volley/request.html

Yash Jain
- 376
- 1
- 3
- 13