我有一个用户可以预订的应用程序。我试图实现一个对话框,用户可以在其中导航定制他的预订,即
我写了一个布局来向用户显示导航步骤(前进,后退,取消等),但我希望上面提到的步骤拥有它自己的片段/布局。我还要提一下,创建对话框的初始调用来自片段。
有谁知道如何实现这一目标?我找到了Fragment-bookingCustomization_DatePicker
错误
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>
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;
}
}
答案 0 :(得分:0)
我写了一个布局来向用户显示导航步骤(前进,后退,取消等),但我希望上面提到的步骤拥有它自己的片段/布局。我还要提一下,创建对话框的初始调用来自片段。
从您的代码中,您试图直接从原始片段开始一个新片段,根据您的要求,这是不可能的。因此,只需注释掉启动新片段的代码将使您的项目有效。
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();
}
如果您想知道如何间接打开其他片段中的片段,可以参考this case。