I have a textView. In my code I am adding some lines of text in it. I also want to display some image from an external URL (not from my resource folder) just in between thos
You are going to probably want to use an asynctask to grab the image. This will run in the background from your other tasks. Your code may look something like this:
public class ImageDownloader extends AsyncTask{
private String url;
private final WeakReference imageViewReference;
//a reference to your imageview that you are going to load the image to
public ImageDownloader(ImageView imageView) {
imageViewReference = new WeakReference(imageView);
}
@Override
protected Bitmap doInBackground(String... arg0) {
if(isCancelled())
return null;
Bitmap retVal;
url = arg0[0];//this is the url for the desired image
...download your image here using httpclient or another networking protocol..
return retVal;
}
@Override
protected void onPostExecute(Bitmap result) {
if (isCancelled()) {
result = null;
return;
}
ImageView imageView = imageViewReference.get();
imageView.setImageBitmap(result);
}
@Override
protected void onPreExecute() {
...do any preloading you might need, loading animation, etc...
}