How To Pass Selected Image From One Fragment To Another Fragment
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 con
Solution 1:
Once Try This , call this at setOnItemClickListener
Fragmentfragment=newImageFullScreen();
Bundlebun=newBundle();
bun.putInt("selected_image", position);
fragment.setArguments(bun);
if (fragment != null) {
FragmentManagerfragmentManager= getFragmentManager();
fragmentManager.beginTransaction().add(R.id.frame_container,fragment).addToBackStack(null).commit();
}
add this at second Fragment ,
Bundlebundle=this.getArguments();
intposition= bundle.getInt("selected_image");;
Toast.makeText(getActivity(), ""+position, 1).show();
Drawableimage=getResources().getDrawable(WallPaperoneFragment.imagefield.get(position));imageView.setImageDrawable(image);
Solution 2:
pass image url fragment to another fragment as argument.. pass as `
another_Fragmentfr=newanother_Fragment();
Bundlebun=newBundle();
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
Post a Comment for "How To Pass Selected Image From One Fragment To Another Fragment"