title: Add imageViews dynamically on Android
body: <p>I want display images from HTML, and I get image url source using <code>Jsoup</code>. But, a problem is that each post has a different number of pictures.
  So, I can't fix the number of ImageViews in xml layout. After I researched, I know that I can create ImageViews dynamically. So, I create <code>ImageViews</code> and insert them into  <code>Linearlayout</code>. But, I can only see one picture which I inserted lastly.</p>
  
  <pre><code>package kr.ac.mju.hanmaeum.activity.notice;
  
  import android.content.Intent;
  import android.media.Image;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.text.Html;
  import android.util.Log;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import com.bumptech.glide.Glide;
  
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.nodes.Element;
  import org.jsoup.select.Elements;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  import kr.ac.mju.hanmaeum.R;
  import kr.ac.mju.hanmaeum.activity.BaseActivity;
  import kr.ac.mju.hanmaeum.utils.Constants;
  
  
  public class NoticeContent extends BaseActivity {
      private String url, title, timestamp, content = "";
      private TextView timestampView, titleView;
      private ImageView contentImageView, contentImageView2;
      private GetImageContentTask getImageContentTask;
      private ArrayList&lt;String&gt; imgList;
      private LinearLayout linearLayout;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_notice_content);
  
          // get intent from MainActivity.
          Intent intent = getIntent();
          url = intent.getStringExtra("URL");
          title = intent.getStringExtra("TITLE");
          timestamp = intent.getStringExtra("TIMESTAMP");
  
          // Set layout contents and I will change this using ButterKnife and detach them to initFunction.
          timestampView = (TextView) findViewById(R.id.contentTimestamp);
          titleView = (TextView) findViewById(R.id.contentTitle);
          contentImageView = (ImageView) findViewById(R.id.contentImage);
          contentImageView2 = (ImageView) findViewById(R.id.contentImage2);
  
          linearLayout = (LinearLayout) findViewById(R.id.content_Linear);
          imgList = new ArrayList&lt;String&gt;();
  
          // get title and timestamp from MainActivity.
          titleView.setText(Constants.NOTICE_TITLE + title);
          timestampView.setText(Constants.NOTICE_TIMESTAMP + timestamp);
  
          getImageContentTask = new GetImageContentTask();
          getImageContentTask.execute();
      }
  
      class GetImageContentTask extends  AsyncTask&lt;Void, Void, ArrayList&lt;String&gt;&gt; {
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
          }
  
          @Override
          protected ArrayList&lt;String&gt; doInBackground(Void... params) {
              try {
                  Document doc = Jsoup.connect(url).timeout(0).get();
  
                  Elements imgs = doc.select("#divView &gt; img");
                  for(Element img : imgs) {
                      imgList.add(img.attr("src"));
                  }
              } catch(IOException e) {
                  e.printStackTrace();
              }
              return imgList;
          }
  
          @Override
          protected void onPostExecute(ArrayList&lt;String&gt; imgList) {
              super.onPostExecute(imgList);
  
              for(int i=0; i&lt; imgList.size(); i++) {
                  ImageView imgView = new ImageView(NoticeContent.this);
                  Glide.with(NoticeContent.this).load(imgList.get(i)).override(200,200).into(imgView);
                  linearLayout.addView(imgView);
              }
          }
      }
  }
  </code></pre>