title: How to refresh a GridView after a onItemClickListener modifies data in an int [] from the ImageAdapter class
body: <p>My <code>GridView</code> is created in my <code>onCreate</code> here:</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          GridView gridview = (GridView) findViewById(R.id.gridview);
          gridview.setAdapter(new ImageAdapter(this));
  ...
  </code></pre>
  
  <p>My <code>ImageAdapter</code> class contains an <code>int[]</code>"images" of <code>R.drawable.</code> references to .png files. I have an onItemClickListener further down in my <code>onCreate</code> that will, depending on where and when my <code>gridview</code> is touched, will update the "images" array. It looks like this, with a lot of extraneous code stripped out:</p>
  
  <pre><code>...
  gridview.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                      int position, long id) {
  
                  while (count &lt;= 6) {
  ...
                      if (count == 2 &amp;&amp; verifyEmpty == false
                              &amp;&amp; choosePiece == true &amp;&amp; chooseEmpty == true) {
                          verifyEmpty = gc.checkEmptyChoice(position);
                          if (verifyEmpty == true) {
                              gc.moveToEmpty(position, gameBoardModel,
                                      (ImageView) v, selectedLocation);
                              count++;
                              // UPDATE THE GRIDVIEW SOMEHOW HERE.
                          }
                          break;
                      }
  ...
  </code></pre>
  
  <p><strong>I want to update my <code>gridview</code> right after the <code>count++</code> inside the nested <code>if</code>. The method right above it, <code>gc.moveToEmpty(...)</code> will make changes to the <code>images</code> array and I want those changes reflected in the <code>gridview</code></strong>.
  I have attempted using <code>notifyDataSetChanged()</code> and <code>invalidateViews</code> but cannot make either of them work from inside my <code>onItemClickListener</code>.</p>
  
  <p>-------------------SOLUTION--------------FROM ANSWER BELOW-----------------</p>
  
  <p>Had to add a name to the ImageAdapter:</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final ImageAdapter iA = new ImageAdapter(this);
  
          GridView gridview = (GridView) findViewById(R.id.gridview);
          gridview.setAdapter(iA);
  ...
  </code></pre>
  
  <p>needed to be final so the the <code>onClick...</code> could use it. Then I could reference it like so:</p>
  
  <pre><code>                    if (verifyEmpty == true) {
                          gc.moveToEmpty(position, gameBoardModel,
                                  (ImageView) v, selectedLocation);
                          count++;
                          // UPDATE THE GRIDVIEW SOMEHOW HERE.
                          // LIKE THIS!
                          iA.notifyDataSetChanged();
                      }
  </code></pre>