title: using grid view and image View to display some images
body: <p>i am creating a simple android application that will display several images  and on the selected one the system will display it in the image view .. but the problem is that the system display the id of the images than on the select of specific image the system display the image in the image view . </p>
  
  <p>can anyone help me to fix this problem ??</p>
  
  <h1>log cat</h1>
  
  <pre><code>12-03 08:57:16.493: E/AndroidRuntime(3126): Caused by: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView
  12-03 08:57:16.493: E/AndroidRuntime(3126):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379)
  </code></pre>
  
  <h1>GridActivity.java</h1>
  
  <pre><code>package com.devleb.listviewdemo;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ArrayAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class GridActivity extends Activity implements
          AdapterView.OnItemClickListener {
  
      private ImageView Selection;
      private static final Integer[] items = { R.drawable.image1,
              R.drawable.image2, R.drawable.image3, R.drawable.image4,
              R.drawable.image5, R.drawable.image6, R.drawable.image4,
              R.drawable.image2 };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_grid);
          Selection = (ImageView) findViewById(R.id.selection);
          GridView grid = (GridView) findViewById(R.id.grid);
          grid.setAdapter(new ArrayAdapter&lt;Integer&gt;(this, R.layout.cell, items));
  
          grid.setOnItemClickListener(this);
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.grid, menu);
          return true;
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
          // TODO Auto-generated method stub
  
          Selection.setImageResource(items[arg2]);
      }
  
  }
  </code></pre>
  
  <h1>activity_grid.xml</h1>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/LinearLayout1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".GridActivity" &gt;
  
      &lt;ImageView
          android:id="@+id/selection"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  
      &lt;GridView
          android:id="@+id/grid"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:columnWidth="100dip"
          android:gravity="center"
          android:horizontalSpacing="5dip"
          android:numColumns="auto_fit"
          android:stretchMode="columnWidth"
          android:verticalSpacing="40dip" &gt;
      &lt;/GridView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <h1>cell.xml</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ImageView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/imgv"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical" &gt;
  
  &lt;/ImageView&gt;
  </code></pre>