更新片段内的ImageView位图

Syl*_*sis 6 android android-fragments

我的部分应用程序使用带有三个片段的ViewPager作为创建事件的"向导".第一个片段包含ImageView中的默认照片和启动AlertDialog的按钮,允许用户拍摄新照片或使用现有照片与事件相关联.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/testing"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:text="Update Crawl Image" 
        android:onClick="fireImageDialog"/>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="278dp"
        android:layout_height="284dp"
        android:layout_gravity="center"
        android:src="@android:drawable/alert_light_frame" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

一旦用户选择了照片,我希望它能够替换默认图像.在fireImageDialog临危的路径,从所选择的图像无论是Intent.ACTION_PICKMediaStore.ACTION_IMAGE_CAPTURE预期,也就是说,我已经证实,返回的路径是一个图像的有效路径.在我的onActivityResult方法结束时,我检索包含上面代码的Fragment并调用一个方法来设置的位图ImageView.

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == LOAD_CRAWL_IMAGE) {
            if (resultCode == RESULT_OK) {
                // Some code here to handle the two potential sources of the path
                // sets `selectedImagePath`
                ((NewCrawlBasicDetailsFragment) getSupportFragmentManager().findFragmentById(R.id.newCrawlBasicDetails)).UpdateImage(selectedImagePath);
            } else if (resultCode != RESULT_CANCELED) {
                Toast.makeText(this, "Failed to load image", Toast.LENGTH_LONG)
                        .show();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

以及相关的UpdateImage方法:

public void UpdateImage(String path){
        if (path.length() > 0) {
            ImageView myPhoto = (ImageView) getView().findViewById(R.id.imageView1);
            myPhoto.setImageBitmap(decodeSampledBitmapFromFile(
                    path, myPhoto.getWidth(),
                    myPhoto.getHeight()));
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的问题是,在所有这些之后,ImageView仍然显示原始默认图像.我试图打电话myPhoto.invalidate()迫使视图重新绘制,但没有任何运气.

有关可能发生的事情的任何建议吗?