title: How to add images to listview which user selects from a gridview of images. I think there is problem with array list animalNewList
body: <p>"I am unable to add images to animalNewList on grid view click"</p>
  
  <pre><code>package com.example.a300287031.lec7_gridview;  
  
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.CheckBox;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.ListView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  
  public class MainActivity extends AppCompatActivity {
  
      GridView myGridView;
      //GridView myGridView = (GridView)findViewById(R.id.grdViewItems);
      ArrayList&lt;Integer&gt; animalList = new ArrayList&lt;&gt;();
      ArrayList&lt;String&gt; animalDescList = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; animalNewList = new ArrayList&lt;&gt;();
     Toast prevToast;
     ListView myList;
  
      public void addItems()
      {
          animalDescList.add("Eagle");
          animalList.add(R.drawable.eagle);
          animalDescList.add("Elephant");
          animalList.add(R.drawable.elephant);
          animalDescList.add("Panda");
          animalList.add(R.drawable.panda);
          animalDescList.add("Panther");
          animalList.add(R.drawable.panther);
          animalDescList.add("Polar");
          animalList.add(R.drawable.polar);
          animalDescList.add("Gorilla");
          animalList.add(R.drawable.gorilla);
      }
  
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          myList=findViewById(R.id.listViewSelectedItems);
          myGridView = (GridView)findViewById(R.id.grdViewItems);
          addItems();
  
          ImageAdapter myAdapter = new ImageAdapter(animalList,this);
          myGridView.setAdapter(myAdapter);
  
          final ImageView imgLarge = (ImageView)findViewById(R.id.imageViewItem);MyCustomAdapter(animalNewList,this);
  
  
  
  
  
  
          myGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  imgLarge.setImageResource(animalList.get(position));
  
                  if (prevToast != null)
                  {
                      prevToast.cancel();
                  }
                  Toast myToast = Toast.makeText(MainActivity.this,animalDescList.get(position),Toast.LENGTH_LONG);
                  myToast.show();
  </code></pre>
  
  <p>Over here I am trying to add images which are selected by the user to new arraylist.  I think they are adding to this:</p>
  
  <pre><code>                animalNewList.add(animalList.get(position));
  
                  prevToast = myToast;
  
  
              }
          });
  </code></pre>
  
  <p>I am setting an adapter over here that should contain an arraylist which only has user selected images from gridview, but its not working.  If I try to add another list which already has images then its working.</p>
  
  <pre><code>        myList.setAdapter(new MyCustomAdapter(animalNewList,this));
  
  
      }
  }
  </code></pre>