title: How do I get the selected item from a Gridview with ImageAdapter? (Android)
body: <p>I had used a ListView to show some data (String) retrieved from the database...quite simple, but one of my cooworkers decided to put an image in front of the text in the screen. We were not able to do it with Listview, but we found some example with GridView that looked exactly as we need then we spent some time using GridView and did put the image in the front of the text.</p>
  
  <p>Now, unfortunately we don't know how to get the selected item (based on the Text that comes from the item selected)</p>
  
  <p>I'm using OnItemClickListener, and within onItemClick the method gridView.getItemSelectedAtPosition(), but everything i get is "null".</p>
  
  <p>I don't now if ImageAdapter has something to do with it, cuz if I change it to an ArrayAdapter I can get the right item properly but there is no image in the row in this way.</p>
  
  <pre><code>gridview.setOnItemClickListener(new OnItemClickListener() {  
     public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id{     String selectedItem = (String) (gridView.getItemAtPosicion(position)); //always null     } });
  </code></pre>
  
  <p>what can I do?</p>
  
  <p>EDITED   - ListView source</p>
  
  <pre><code>import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  public class ImageAdapter extends BaseAdapter {
  private Context context;
  private final String[] mobileValues;
  private final String[] mobileValuesD;
  
  public ImageAdapter(Context context, String[] mobileValues, String[] mobileValuesD) {
  this.context = context;
  this.mobileValues = mobileValues;
  this.mobileValuesD = mobileValuesD;
  }
  
    public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater inflater = (LayoutInflater) context.getSystemService           (Context.LAYOUT_INFLATER_SERVICE);
    View gridView;
  
    if (convertView == null) {
  
    gridView = new View(context);
  
     // get layout from mobile.xml
      gridView = inflater.inflate(R.layout.pesquisa_2, null);
  
    // set value into textview
      TextView textView = (TextView) gridView.findViewById(R.id.grid_item_label);
       textView.setText(mobileValues[position]+"\n"+mobileValuesD[position]);
  
   // set image based on selected text
    ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);
  
    String mobile = mobileValues[position];
  
   //SELECT DAS IMAGENS
  
    if (mobile.equals("pdt1")) {
       imageView.setImageResource(R.drawable.img1);
    } else if (mobile.equals("prd2")) {
        imageView.setImageResource(R.drawable.feijao);
     } else {
         imageView.setImageResource(R.drawable.acucar);
      }
  
  
     } else {
      gridView = (View) convertView;
     }
  
      return gridView;
   }
  
     public int getCount() {
          return mobileValues.length;
   }
  
    public Object getItem(int position) {
        return null;
   }
  
     public long getItemId(int position) {
        return 0;
   }
  
   }
  </code></pre>