title: Why isn't async stopping from recreating listview?
body: <p>Wasn't really sure how to ask this but...</p>
  
  <p>My code is meant to generate ListView input on a button click.</p>
  
  <p>When I click the button it should .execute() an Async which takes a list of items and adds them to an ArrayList&lt; HashMap &lt; String, String > > with a custom adapter.</p>
  
  <p>The problem is, when I press the button, it generates the list and adds it to the ListView, however, instead of going... 1, 2, 3, 4, 5, ....20 it goes in a random order. 1, 2, 5, 1, 3, 0, 6, 7, 8, 3, 1 ...</p>
  
  <p>And if I scroll up or down the ListView it changes.</p>
  
  <p>activity_main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/activity_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      tools:context=".MainActivity"&gt;
  
      &lt;Button
          android:id="@+id/bLoadData"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:text="Load api data" /&gt;
  
      &lt;ListView
          android:id="@+id/lvMovies"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_above="@id/bLoadData"
          android:background="#efefef" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>results_layout.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"&gt;
  
  
          &lt;ImageView android:id="@+id/ivPosters"
              android:layout_width="120dp"
              android:layout_height="120dp"
              android:src="@drawable/place_holder_img"/&gt;
  
          &lt;TextView
              android:id="@+id/results_layout_tv_movie_name"
              android:layout_width="0dp"
              android:layout_height="fill_parent"
              android:layout_weight="1"
              android:paddingBottom="10dp"
              android:paddingLeft="20dp"
              android:paddingStart="20dp"
              android:paddingTop="10dp"
              android:text="hellow"
              android:textColor="#000"
              android:textSize="20sp" /&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>MainActivity.class:</p>
  
  <pre><code>package com.example.zdroa.testinggrounds;
  
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.Button;
  import android.widget.ListView;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  public class MainActivity extends AppCompatActivity {
  
      static ArrayList&lt;HashMap&lt;String, String&gt;&gt; posters;
      ListView listView;
      Button button;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          listView = (ListView) findViewById(R.id.lvMovies);
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  System.out.println(posters.get(position).values().toString());
              }
          });
  
          button = (Button) findViewById(R.id.bLoadData);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  posters = new ArrayList&lt;&gt;();
                  ImageLoadTask ilt = new ImageLoadTask();
                  ilt.execute();
              }
          });
      }
  
  
      private class ImageLoadTask extends AsyncTask&lt;Void, Void, ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt; {
  
          @Override
          protected ArrayList&lt;HashMap&lt;String, String&gt;&gt; doInBackground(Void... params) {
  
              posters = getPathFromAPI();
              return posters;
          }
  
          @Override
          protected void onPostExecute(ArrayList&lt;HashMap&lt;String, String&gt;&gt; result) {
              SearchAdapter adapter = new SearchAdapter(MainActivity.this, result);
              listView.setAdapter(adapter);
          }
  
          private ArrayList&lt;HashMap&lt;String, String&gt;&gt; getPathFromAPI() {
              String moviePaths[] = new String[10];
  
              for (int i = 0; i &lt; moviePaths.length; i++) {
                  HashMap&lt;String, String&gt; map = new HashMap&lt;&gt;();
                  String s = "path";
                  map.put(s, s + "_" + i);
                  moviePaths[i] = "path_" + i;
                  posters.add(map);
              }
              return posters;
          }
      }
  }
  </code></pre>
  
  <p>SearchAdapter.class:</p>
  
  <pre><code>package com.example.zdroa.testinggrounds;
  
  import android.content.Context;
  import android.graphics.drawable.Drawable;
  import android.support.v4.content.ContextCompat;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import com.squareup.picasso.Picasso;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  public class SearchAdapter extends BaseAdapter {
  
      private Context mContext;
      private ArrayList&lt;HashMap&lt;String, String&gt;&gt; array;
      private ImageView imageView;
      private TextView textView;
  
      SearchAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; paths) {
          mContext = context;
          array = paths;
      }
  
      @Override
      public int getCount() {
          return array.size();
      }
  
      @Override
      public Object getItem(int position) {
          return null;
      }
  
      @Override
      public long getItemId(int position) {
          return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          if (convertView == null) {
              convertView = View.inflate(mContext, R.layout.results_layout, null);
              imageView = (ImageView) convertView.findViewById(R.id.ivPosters);
              textView = (TextView) convertView.findViewById(R.id.results_layout_tv_movie_name);
          }
  
          Drawable drawable = ContextCompat.getDrawable(mContext, R.drawable.place_holder_img);
  
          String link_end = array.get(position).values().toString();
          Picasso.with(mContext)
                  .load("http://image.tmdb.org/t/p/w185" + link_end)
  //                .resize(width, (int) (width * 1.5))
                  .placeholder(drawable)
                  .into(imageView);
  
  
          textView.setText(position+"");
  
          return convertView;
      }
  }
  </code></pre>