从中选择图像的第一个片段
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();
第二个片段接收图像并显示
String bbb = getArguments().getString("Image");
Bitmap bitmap = BitmapFactory.decodeFile(bbb);
iv.setImageBitmap(bitmap);
答案 0 :(得分:6)
将文件路径发送到下一个片段
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();
在你的NextFragment中你可以收到它并设置如下
String imgPath = getArguments().getString("Image");
Bitmap bitmap = BitmapFactory.decodeFile(new File(imgPath));
iv.setImageBitmap(bitmap);
答案 1 :(得分:1)
尝试将您的捆绑包放在第二个片段中
Bundle bundle = this.getArguments();
if (bundle != null) {
String s = bundle.getString(key, defaulValue);
}
另请查看此链接以获取进一步的参考 Passing bundle in fragments
答案 2 :(得分:0)
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));
}