I have a grid of many products in my app. when the user selects one of the item in the grid, I am starting a new activity as DIALOG box and display the item\'s name,quantity
i had the same problem and solve it with passing the position of selected item via intent. as i think and read from professionals in stack its the best solution. just do that in FirstActivity.java that Contains GridView
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(),DetailActivity.class);
intent.putExtra("id",position);
startActivity(intent); } });
and then in your destination Activity you must get the position from extras and extract it from your database or where your images array are cast:
Intent intent = getActivity().getIntent();
int position = intent.getIntExtra("id",0);
ImageAdapter imageAdapter = new ImageAdapter(getActivity());
ImageView imageView = (ImageView)rootView.findViewById(R.id.movie_detail_image);
imageView.setImageResource((int)imageAdapter.getItem(position));
you must edit your image adapter getItem method to return selected image id.