Alert dialog with custom layout cant find controls

Hi all
I'm very new to xamarin and andriod and im stuck with on a small problem

I am creating a custom dialog and inflating it but i cant seem to acces the controls on the alert dialog

i cant access the SignaturePadView after the button has been pressed

    private void SignV(string title)
    {
        View view = LayoutInflater.Inflate(Resource.Layout.SignView, null);
        AlertDialog builder = new AlertDialog.Builder(this).Create();
        builder.SetTitle(title);
        builder.SetView(view);
        builder.SetCanceledOnTouchOutside(false);

        Button btnSignR = view.FindViewById<Button>(Resource.Id.btnSignIssue);
        btnSignR.Text = title;
        btnSignR.Click += delegate
        {
            SignaturePadView sg = FindViewById<SignaturePadView>(Resource.Id.spcIssue);
            if (btnSignR.Text == "Receiver")
            {
                Rimage = sg.GetImage();
            }
            else
            {
                Iimage = sg.GetImage();
            }
            builder.Dismiss();
            if (Rimage == null && Iimage == null)
            {
                IssueSQL();
            }
        };
        builder.Show();
    }

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I don't know Android very well.

    Is SignaturePad inside the AlertDialog? Because, if you use

    view.FindViewById
    

    to access the button, I think you have to use the same to access the SignaturePad

  • StephenvanSittertStephenvanSittert USMember ✭✭

    Yes the signature pad is inside the AlertDialog
    If i do that I get the following error

    System.InvalidCastException: Unable to convert instance of type
    'Xamarin.Controls.SignaturePadCanvasView' to type
    'Xamarin.Controls.SignaturePadView'.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    how is your xaml?

  • StephenvanSittertStephenvanSittert USMember ✭✭
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Xamarin.Controls.SignaturePadCanvasView
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="373.5dp"
            android:id="@+id/spcIssue" />
        <Button
            android:text="Submit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnSignIssue" />
    </LinearLayout>
    
  • StephenvanSittertStephenvanSittert USMember ✭✭

    Thank you this fixed
    Stupid oversight on my part

Sign In or Register to comment.