0

I have an app where the user can make bookings. I'm trying to implement a dialog where the user can navigate through customizing his booking, i.e.

  1. Pick the date
  2. Add extras
  3. View quote
  4. Confirm Booking

I wrote a layout to display navigation steps to the user (forward, back, cancel etc), but I want the steps mentioned above to have it's own fragment/layout. I should also mention that the initial call to create the dialog is from a fragment. Does anyone know how to achieve this? I get a No view found for Fragment-bookingCustomization_DatePicker error

private Dialog dialog;
private void BtnMakeBooking_Click(object sender, EventArgs e)
{
    dialog = new Dialog(this.Activity);
    dialog.RequestWindowFeature((int)WindowFeatures.ContextMenu);
    dialog.SetTitle("Booking Customization");
    dialog.SetContentView(Resource.Layout.Fragment_booking_customization);

    Fragment_bookingCustomization_DatePicker date = new Fragment_bookingCustomization_DatePicker();
    var fragManager = FragmentManager.BeginTransaction();
    fragManager.Replace(Resource.Id.relativeLayout1, date);
    fragManager.Commit();

    dialog.Show();
}

Fragment_booking_customization.axml

<?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="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px">
    <RelativeLayout
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/relativeLayout1" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:orientation="horizontal"
        android:layout_weight="1">
        <Button
            android:text="Back"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:layout_weight="1"
            android:background="@drawable/red_button"
            android:drawableLeft="@drawable/ic_action_previous_item"
            android:id="@+id/btn_bookingcustomization_cancel" />
        <Button
            android:text="Next"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:layout_weight="1"
            android:background="@drawable/red_button"
            android:drawableRight="@drawable/ic_action_next_item"
            android:id="@+id/btn_bookingcustomization_next" />
    </LinearLayout>
    <Button
        android:text="Confirm Booking"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/red_button"
        android:drawableRight="@drawable/ic_action_accept"
        android:id="@+id/btn_bookingcustomization_confirm"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="4dp" />
    <Button
        android:text="Cancel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="4dp"
        android:background="@drawable/red_button"
        android:drawableRight="@drawable/ic_action_remove"
        android:id="@+id/btn_bookingcustomization_cancel" />
</LinearLayout>

enter image description here

Fragment_bookingCustomization_DatePicker.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px">
    <DatePicker
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/datePicker1" />
</LinearLayout>

Fragment_bookingCustomization_DatePicker.cs

public class Fragment_bookingCustomization_DatePicker : Fragment
{
    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your fragment here
    }

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View rootView = inflater.Inflate(Resource.Layout.Fragment_bookingCustomization_DatePicker, container, false);
        return rootView;
    }
}
Code Vader
  • 739
  • 3
  • 9
  • 26

1 Answers1

0

I wrote a layout to display navigation steps to the user (forward, back, cancel etc), but I want the steps mentioned above to have it's own fragment/layout. I should also mention that the initial call to create the dialog is from a fragment.

From your codes, you are trying to start a new fragment directly from the original fragment, which is not possible also not necessary according to your requirement. So simply comment out the codes of starting a new fragment will make your project work.

private void BtnClick_Click(object sender, EventArgs e)
{
    dialog = new Dialog(this.Activity);
    dialog.RequestWindowFeature((int)WindowFeatures.ContextMenu);
    dialog.SetTitle("Booking Customization");
    //here your dialog already host it's own layout:
    dialog.SetContentView(Resource.Layout.Fragment_booking_customization);

    //You can't start a new fragment from this fragment. So just comment the following codes out
    //Fragment_bookingCustomization_DatePicker date = new Fragment_bookingCustomization_DatePicker();
    //var fragManager = FragmentManager.BeginTransaction();
    //fragManager.Replace(Resource.Id.relativeLayout1, date);//error
    //fragManager.Commit();

    dialog.Show();
}

If you want to know how to open a fragment from other fragment indirectly, you can refer to this case.

Community
  • 1
  • 1
Elvis Xia - MSFT
  • 10,801
  • 1
  • 13
  • 24