title: How to refresh a child view in a GridView?
body: <p>I have a <code>GridView</code> showing some <code>TextView</code>s, the views are drawn so that <strong>ONE</strong> is marked as selected. The problem is that when the user interaction changes the selected item in my logic I want to update the views involved, namely <em>the view showing previous selected item</em> and <em>the view showing the current selected item</em>. (Of course in my real problem the child views in the grid are more complex as well as the update process which could involve some calculations, loading of resources, accessing databases, etc.)</p>
  
  <p>Till now I'm using <code>BaseAdapter.notifyDataSetChanged</code> or <code>GridView.invalidateViews</code> and both do the work but also updates <strong>ALL</strong> the visible child views of the <code>GridView</code> but what I want is to update just <strong>TWO</strong> views among them.</p>
  
  <p>How can I do that? How to get just the two views for the updating process?</p>
  
  <p>Note: I'm facing this problem with <code>ListView</code>s also but I think maybe it will have the same solution.</p>
  
  <p>Example code:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      private int selectedPos = 36;
  
      private class MyAdapter extends BaseAdapter {
          @Override
          public int getCount() {
              return 100;
          }
          @Override
          public Object getItem(int position) {
              return position;
          }
          @Override
          public long getItemId(int position) {
              return position;
          }
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              TextView tv;
              if(convertView==null) {
                  tv = new TextView(MainActivity.this);
              } else {
                  tv = (TextView) convertView;
              }
              Log.d("Updating -----", String.valueOf(position));
              if(position==selectedPos)
                  tv.setText("Item ".toUpperCase() + String.valueOf(position));
              else
                  tv.setText("Item " + String.valueOf(position));             
              return tv;
          }       
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final GridView gv = (GridView) findViewById(R.id.gridView1);
          gv.setAdapter(new MyAdapter());
          gv.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  selectedPos = position;
                  //gv.invalidateViews();
                  ((MyAdapter)gv.getAdapter()).notifyDataSetChanged();
              }
          });
  
      }    
  }
  </code></pre>
  
  <p>What I'm looking for is something like (some kind of pseudo code):</p>
  
  <pre><code>updateThisViewAsNotSelected(selectedPos);
  gv.redrawThisView(selectedPos);
  selectedPos = position;
  updateThisViewAsSelected(selectedPos);
  gv.redrawThisView(selectedPos);
  </code></pre>