如何在popBackStack()之后显示加载Picasso的图像

时间:2016-12-27 13:31:48

标签: android android-fragments imageview picasso

我有第一个用Picasso以这种方式加载imageView的片段:

 ExifInterface exif = null;
                float rotate = 0;

                try
                {
                    exif = new ExifInterface(absolutePath);
                } catch (IOException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_UNDEFINED);
                switch (orientation) {
                    case ExifInterface.ORIENTATION_NORMAL:
                        rotate = 0;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        rotate = 270;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        rotate = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        rotate = 90;
                        break;
                }


                Picasso.with(getActivity())
                        .load(mMediaUri)
                        .resize(1280, 1280)
                        .rotate(rotate)
                        .centerCrop()
                        .transform(new RoundedTransformation())
                        .into(photo);

当我按下next按钮时,我执行此操作,然后转到第二个片段:

      Bundle bundle = new Bundle();
                              bundle.putLong("primaryKey", primaryKey);
                              bundle.putString("uri", String.valueOf(mMediaUri));
                              bundle.putString("registration", registrationET.getText().toString().trim());
                              bundle.putString("makemodel", makemodelET.getText().toString().trim());
                              bundle.putString("manifacturer", manifacturerET.getText().toString().trim());
                              bundle.putString("category", categoryET.getText().toString().trim());
                              bundle.putString("class", classET.getText().toString().trim());

                              Fragment fragment = new AddAircraftSecondPartFragment();
                              fragment.setArguments(bundle);

                              FragmentManager manager = getActivity().getSupportFragmentManager();
                              manager.beginTransaction().replace(R.id.content_main, fragment).addToBackStack(null).commit();

当我想要按回或点击Back按钮时会出现问题:EditTextTextView上的值是正确的,因为我使用了这个:

android:freezesText="true"

但我没有在ImageView中看到先前的图像加载了Picasso。 这是我用于popBackStack()的代码:

 private void pressBackButton()
{
    FragmentManager manager = getActivity().getSupportFragmentManager();

    manager.popBackStack();

}

所以我的问题是:

  1. 我怎么能解决ImageView的问题?
  2. popBackStack()之后的前一个片段中调用的方法是什么?
  3. 感谢您的回答

1 个答案:

答案 0 :(得分:1)

1)您可以移动图像加载以覆盖片段的onResume()方法。

2)当片段被"恢复时,调用onResume()"