title: ANDROID- how to save selected item from gridView in a string?
body: <p>I am showing captured images in one layout using different gridView for each category (Shirts , Trousers e.t.c). The number of the gridViews is 6.</p>
  
  <p>I am trying to select one image from each gridView and via onClick method in the button to show them in another activity but the code i wrote doesn't work. </p>
  
  <p>I suppose something is wrong with the strings.</p>
  
  <p>Can anyone help me to fix this? Thnak you in advance!</p>
  
  <pre><code>public class CreateOutfit extends Activity implements View.OnClickListener {
  
  private DatabaseHandler handler;
  
  GridView grid1;
  GridView grid2;
  
  
  ArrayList&lt;Clothes&gt; clothes = new ArrayList&lt;Clothes&gt;();
  GridviewAdapter GridAdapter;
  
  String image1;
  String image2;
  
  
  public static final String ITEM_IMAGE1 = "image1";
  
  public static final String ITEM_IMAGE2 = "image2";
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.clothes_grids);
  
      handler = new DatabaseHandler(getApplicationContext());
  
      grid1 = (GridView) findViewById(R.id.grid1);
      grid1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              image1 = String.valueOf(view.findViewById(R.id.cloth_image_grid).getContext().toString());
  
  
          }
      });
  
      fillGrid1();
  
      grid2 = (GridView) findViewById(R.id.grid2);
      grid2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              image2 = String.valueOf(view.findViewById(R.id.cloth_image_grid));
  
          }
      });
  
      fillGrid2();
  
  
      ImageButton btn_in = (ImageButton)findViewById(R.id.btn_insert);
      btn_in.setOnClickListener(this);
  
  
  }
  
  
  public void fillGrid1() {
  
      clothes = (ArrayList&lt;Clothes&gt;) handler.readGridShirts();
  
      GridAdapter = new GridviewAdapter(this, R.layout.grid_row, clothes);
  
      grid1.setAdapter(GridAdapter);
  
      for (Clothes c : clothes) {
          String record = "ID=" + c.getID() + " | Category=" + c.getCategory() + " | " + c.getSize();
          Log.d("Record", record);
      }
  }
  
  public void fillGrid2() {
  
      clothes = (ArrayList&lt;Clothes&gt;) handler.readGridTrousers();
  
      GridAdapter = new GridviewAdapter(this, R.layout.grid_row, clothes);
  
      grid2.setAdapter(GridAdapter);
  
      for (Clothes c : clothes) {
          String record = "ID=" + c.getID() + " | Category=" + c.getCategory() + " | " + c.getSize();
          Log.d("Record", record);
      }
  }
  
  
  @Override
  public void onClick(View v) {
  
      Intent in = new Intent(getApplicationContext(), ViewOutfit.class);
  
      in.putExtra(ITEM_IMAGE1 , image1);
  
      in.putExtra(ITEM_IMAGE2, image1);
  
      startActivity(in);
  
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class ViewOutfit extends Activity {
  
  DatabaseHandler handler;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.view_outfit);
  
      Intent i = getIntent();
  
      handler = new DatabaseHandler(getApplicationContext());
  
      ImageView im1 = (ImageView) findViewById(R.id.im1);
      String image1 = i.getStringExtra("image1");
      im1.setImageBitmap(BitmapFactory.decodeFile(i.getStringExtra(image1)));
  
      ImageView im2 = (ImageView) findViewById(R.id.im2);
      String image2 = i.getStringExtra("image2");
      im2.setImageBitmap(BitmapFactory.decodeFile(i.getStringExtra(image2)));
  
  
  }
  </code></pre>