【发布时间】:2017-02-20 07:38:10
【问题描述】:
我的 Activity 中有一个位图图像,如下所示:
Bitmap image4 = BitmapFactory.decodeResource(getResources(), R.drawable.hello);
image1.setImageBitmap(image4);
我正在尝试使用此代码在片段中传递此图像:
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.addToBackStack(null);
Secondfrag yourFragment = new Secondfrag();
Bundle b = new Bundle();
b.putParcelable("BitmapImage",image4);
yourFragment.setArguments(b);
fragmentTransaction.add(R.id.frag, yourFragment, "FRAGMENT");
fragmentTransaction.commit();
并尝试在片段中获取此图像:
Bundle b=this.getArguments();
String page=b.getString("BitmapImage");
image2.setImageURI(Uri.parse(page));
但是我的 Fragment 中没有图像显示。如何解决这个问题?
【问题讨论】:
-
我认为传递参考是个好主意
-
正如@TahmidRahman 所说,您可以通过参考:)
-
您可以通过保存在内部存储中来做到这一点..
标签: android android-fragments bitmap android-imageview android-image