title: Set Background in GridView by item position
body: <p>I want to change the background color for specific item in GridView (by position).</p>
  
  <pre><code>gridview.getChildAt(1).setBackgroundResource(android.R.drawable.btn_default);
  </code></pre>
  
  <p>doesn't work.</p>
  
  <p>If I use it in OnClickListener it works:</p>
  
  <pre><code>public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                  int position, long id) {
      view.setBackgroundResource(android.R.drawable.btn_default);
  }
  </code></pre>
  
  <p>but I want to change it without a click.</p>
  
  <hr>
  
  <p><em>EDIT</em></p>
  
  <p><strong>ImageAdapter:</strong></p>
  
  <pre><code>public class ImageAdapter extends BaseAdapter {
  private final String TAG = getClass().toString();
  
  private Context mContext;
  
  public ImageAdapter(Context c) {
      mContext = c;
  }
  
  public int getCount() {
      return mThumbIds.length;
  }
  
  public Object getItem(int position) {
      return null;
  }
  
  public long getItemId(int position) {
      return 0;
  }
  
  public View getView(int position, View convertView, ViewGroup parent) {
      ImageView imageView;
      if (convertView == null) {  // if it's not recycled, initialize some attributes
          imageView = new ImageView(mContext);
          imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
          imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
          imageView.setPadding(8, 8, 8, 8);
      } else {
          imageView = (ImageView) convertView;
      }
  
      parent.getChildAt(1).setBackgroundColor(Color.RED);
  
      imageView.setImageResource(mThumbIds[position]);
      return imageView;
  }
  </code></pre>
  
  <p><strong>Activity:</strong></p>
  
  <pre><code>final GridView gridview = (GridView) view.findViewById(R.id.gridView);
  gridview.setAdapter(new ImageAdapter(MainActivity.this));
  gridview.setSelection(0);
      gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      View previous = null;
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                  int position, long id) {
              if(previous == view) {
                  view.setBackgroundResource(android.R.drawable.btn_default);
              } else {
                  view.setBackgroundResource(android.R.drawable.btn_default);
                  if(previous != null) previous.setBackgroundResource(0);
                  previous =  view;
              }
  
          }
      });
  </code></pre>
  
  <p><strong>XML:</strong></p>
  
  <pre><code>&lt;GridView
      android:id="@+id/gridView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center"
      android:numColumns="4" &gt;
  &lt;/GridView&gt;
  </code></pre>