我有以下代码:
Button schedend = FindViewById<Button>(Resource.Id.buttonschede);
schedend.Click += schedend_Click;
}
void schedend_Click(object sender, EventArgs e)
{
Dialog dialog = new Dialog(this);
dialog.SetContentView(Resource.Layout.DateTimePickerTemplate);
dialog.SetTitle("Pick date and time");
TimePicker tp = FindViewById<TimePicker>(Resource.Id.timePicker1);
Button butadd = FindViewById<Button>(Resource.Id.buttonadd);
//tp.SetOnTimeChangedListener(onTimeChangedListener: retain());
// tp.SetIs24HourView(new Boolean(true));
butadd.Click += butadd_Click;
//tp.SetIs24HourView(true);
dialog.Show();
}
private void retain()
{
}
void butadd_Click(object sender, EventArgs e)
{
EditText edittxt = FindViewById<EditText>(Resource.Id.editschstart);
edittxt.Text = e.ToString();
}
我有一个自定义对话框,带有日期和时间选择器
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2">
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="Add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonadd" />
<Button
android:text="Cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/buttoncancel" />
</LinearLayout>
</ScrollView>
</LinearLayout>
我尝试了不同的方法,但没有成功,我怎样才能保留设置的日期和时间,将其保留在变量中,当我单击对话框中的添加按钮时,我将它们保存在编辑文本中?我是新手,需要一些帮助。Thx