title: Showing images from HTML to TextView - Android
body: <p>I'm using AsuncTask for getting JSON from web service. From JSON I get "title" and "fulltext".
  "title" is simple text, but "fulltext" is HTML text. In this HTML I have some text and URLs with images. I want to show whole HTML in TextView.</p>
  
  <p>My code:</p>
  
  <pre><code>    TextView tvArticleTitle = (TextView) findViewById(R.id.tvArticleTitle);
      TextView tvArticleText = (TextView) findViewById(R.id.tvArticleText);
  
  public class GetArticleTask extends AsyncTask&lt;String, Void, Boolean&gt; {
  
          private String title;
          private String text;
          private ProgressDialog dialog;
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
  
              dialog = new ProgressDialog(context);
              dialog.setMessage("Please wait!");
              dialog.setCancelable(false);
              dialog.show();
          }
  
          @Override
          protected Boolean doInBackground(String... params) {
  
              try {
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpPost httpPost = new HttpPost(Variables.URL_ARTICLE);
                  httpPost.setEntity(new UrlEncodedFormEntity(pair));
  
                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  String data = EntityUtils.toString(httpEntity);
  
                  int status = httpResponse.getStatusLine().getStatusCode();
  
                  if (status == HttpStatus.SC_OK) {
  
                      JSONObject jRealObject = new JSONObject(data);
  
                      title = jRealObject.getString("title").toString();
                      text = jRealObject.getString("fulltext").toString();
  
                      return true;
                  }
              } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              } catch (ClientProtocolException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              } catch (JSONException e) {
                  e.printStackTrace();
              }
              return false;
          }
  
          @Override
          protected void onPostExecute(Boolean result) {
              super.onPostExecute(result);
  
              if (result == false) {
                  Toast.makeText(context, Variables.ERROR_MESSAGE, Toast.LENGTH_SHORT).show();
              } else {
  
                  tvArticleTitle.setText(title);
                  tvArticleText.setText(Html.fromHtml(text, new ImageGetter() {
  
                      @Override
                      public Drawable getDrawable(String source) {
  
                          Drawable drawable = null;
                          URL sourceURL;
  
                          try {
                              sourceURL = new URL(source);
                              URLConnection urlConnection = sourceURL.openConnection();
                              urlConnection.connect();
                              InputStream inputStream = urlConnection.getInputStream();
                              BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
                              Bitmap bm = BitmapFactory.decodeStream(bufferedInputStream);
  
                              // convert Bitmap to Drawable
                              drawable = new BitmapDrawable(getResources(), bm);
  
                              drawable.setBounds(0, 0, bm.getWidth(), bm.getHeight());
                          } catch (MalformedURLException e) {
                              e.printStackTrace();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
  
                          return drawable;
                      }
  
                  }, null));
  
                  if(dialog.isShowing()) {
                      dialog.dismiss();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>It gives me error: android.os.NetworkOnMainThreadException. I know that I need to make this on AsyncTask again, but I don't know how to split code. </p>