[英]Passing image from one fragment to a another fragment and display image in that fragment
First fragment from which image is selected 从中选择图像的第一个片段
iv.setImageURI(Uri.fromFile(pictureFile));
String stringUri;
stringUri = pictureFile.toString();
FreeFragment ldf = new FreeFragment ();
Bundle args = new Bundle();
args.putString("Image", stringUri);
ldf.setArguments(args);
Log.d("Passing image", String.valueOf(args));
getFragmentManager().beginTransaction().add(R.id.container, ldf).commit();
Second fragment receiving image and displaying it 第二个片段接收图像并显示
String bbb = getArguments().getString("Image");
Bitmap bitmap = BitmapFactory.decodeFile(bbb);
iv.setImageBitmap(bitmap);
Send file path to next Fragment 发送文件路径到下一个片段
String stringUri = pictureFile.getAbsolutePath();
FreeFragment ldf = new FreeFragment ();
Bundle args = new Bundle();
args.putString("Image", stringUri);
ldf.setArguments(args);
getFragmentManager().beginTransaction().add(R.id.container, ldf).commit();
In your NextFragment u can receive it and set as below 在您的NextFragment中,您可以接收它并进行如下设置
String imgPath = getArguments().getString("Image");
Bitmap bitmap = BitmapFactory.decodeFile(new File(imgPath));
iv.setImageBitmap(bitmap);
Try getting your bundle in second fragment like this 尝试像这样在第二个片段中获取捆绑包
Bundle bundle = this.getArguments();
if (bundle != null) {
String s = bundle.getString(key, defaulValue);
}
Also check this link for further references Passing bundle in fragments 还要检查此链接以获取更多参考。
Bundle bundle = this.getIntent().getExtras();
String strPic = bundle.getString("Image");
File picFile = new File("your file path"+strPic);
if(picFile.exists())
{
iv.setImageURI(Uri.fromFile(picFile));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.