1

I want to pass the single Image from one Fragment to another Fragment, where the Images are placed in GridView of one Fragment and have to set them as background of FrameLayout contained in another Fragment,, Thanks,,

Akshay
  • 6,029
  • 7
  • 40
  • 59
  • pass the resource id from fragment to fragment using the associated activity. Use a interface as a callback to the activity – Raghunandan Feb 14 '14 at 06:10
  • Pass the resource id through bundle to another fragment. Bundle args = new Bundle(); args.putInt("index", resouce_id); f.setArguments(args); and access the arguments getArguments().getInt("index", 0); – Dasari Feb 14 '14 at 06:17
  • But how can I get resource id of image from GridView??? – Akshay Feb 14 '14 at 06:22
  • How you are setting images to gridview? – Dasari Feb 14 '14 at 06:41
  • @Dasari Using ImageAdapter.. – Akshay Feb 14 '14 at 06:43
  • you mean from gallery you are accessing the images and setting to the gridview? – Dasari Feb 14 '14 at 06:47
  • In ImageAdapter also u have to set image resouce to image view like imageView.setImageResource(resourceId); The resource id you have to pass to the fragment. – Dasari Feb 14 '14 at 06:51

2 Answers2

1

Once Try This , call this at setOnItemClickListener

Fragment fragment = new ImageFullScreen();
Bundle bun = new Bundle();
bun.putInt("selected_image", position);
fragment.setArguments(bun);
if (fragment != null) {
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().add(R.id.frame_container,fragment).addToBackStack(null).commit();

}

add this at second Fragment ,

Bundle bundle = this.getArguments();
int position = bundle.getInt("selected_image");;
Toast.makeText(getActivity(), ""+position, 1).show();
Drawable image  =getResources().getDrawable(WallPaperoneFragment.imagefield.get(position));imageView.setImageDrawable(image);
R KiranKumar
  • 825
  • 1
  • 8
  • 27
0

pass image url fragment to another fragment as argument.. pass as `

another_Fragment fr = new another_Fragment();
 Bundle bun = new Bundle();
 bun.putString("selected_image", image_url);
 fr.setArguments(bun);`

and get value as String image_url=getArguments().getString("selected_image"); in anothe_fragment`

or use interface to communicate

Shijil
  • 2,226
  • 18
  • 33