Why won't my Imageview update when I select an image from the gallery?

asusmaniasusmani Member ✭✭

Hello,
I am trying to select an image from the photo gallery and display it in my ImageView control.
When I select it, the code doesn't throw any errors, but the image I selected does NOT show in the imageView....

Anyone have any idea's what might be going on?

Here is my XAML:

<?xml version="1.0" encoding="utf-8"?>


        <ImageView
            android:src="@android:drawable/ic_menu_gallery"
            android:id="@+id/imgAddPaint" 
            android:layout_width="match_parent" 
            android:layout_height="200dp"/>
        <Button
            android:text="Browse Photo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cmdAddPaint"
            android:textStyle="bold"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp" />          
    </TableLayout>
</ScrollView>

Below is my Code:

Common CM = new Common();        
    public static readonly int PickImageId = 1000;
    private ImageView imgPaint;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        initializeView();
    }
    protected override void OnStart()
    {
        base.OnStart();
        initializeView();
    }
    public void initializeView()
    {
        SetContentView(Resource.Layout.AdminAddPaint);
        // Create your application here            

        //Browse Button
        Android.Widget.Button BrowseButton = FindViewById<Android.Widget.Button>(Resource.Id.cmdAddPaint);
        BrowseButton.Click += ButtonOnClick;

        //imageview
        imgPaint = FindViewById<ImageView>(Resource.Id.imgAddPaint);
    }

private void ButtonOnClick(object sender, EventArgs e)
{
Intent = new Intent();
Intent.SetType("image/*");
Intent.PutExtra(Intent.ExtraAllowMultiple, true);
Intent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(Intent, "Select Photo"), PickImageId);
}

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        if ((requestCode == PickImageId) && (resultCode == Result.Ok) && (data != null))
        {           

                Android.Net.Uri uri = data.Data;                    
                 imgPaint.SetImageUri(uri);
        }

    }

Best Answers

  • asusmaniasusmani ✭✭
    Accepted Answer

    Thanks Yelinzh.
    It turns out that my view was being recreated because I had an override for onStart.

Answers

  • asusmaniasusmani Member ✭✭
    Accepted Answer

    Thanks Yelinzh.
    It turns out that my view was being recreated because I had an override for onStart.

Sign In or Register to comment.