1
次の例のように私は次のように従っていますhttps://developer.xamarin.com/guides/android/user_interface/date_picker/しかし、エラーが表示されます: 'NewInstance'タイプが 'DatePickerFragment'タイプに存在しません'NewInstance'タイプが 'DatePickerFragment'タイプに存在しません
どこに間違っているのか誰にでも見られますか?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Util;
namespace AndroidApp
{
public class DatePickerFragment : DialogFragment, DatePickerDialog.IOnDateSetListener
{
public static readonly string TAG = "X:" + typeof(DatePickerFragment).Name.ToUpper();
Action<DateTime> _dateSelectedHandler = delegate { };
public static DatePickerFragment NewInstance(Action<DateTime> onDateSelected)
{
DatePickerFragment frag = new DatePickerFragment();
frag._dateSelectedHandler = onDateSelected;
return frag;
}
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
DateTime currently = DateTime.Now;
DatePickerDialog dialog = new DatePickerDialog(Activity,
this,
currently.Year,
currently.Month,
currently.Day);
return dialog;
}
public void OnDateSet(DatePicker view, int year, int monthOfYear, int dayOfYear)
{
DateTime seletedDate = new DateTime(year, monthOfYear + 1, dayOfYear);
Log.Debug(TAG, seletedDate.ToLongDateString());
_dateSelectedHandler(seletedDate);
}
}
}
public class MainActivity : Activity
{
TextView _dateDisplay;
Button _dateSelectedButton;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
//DatePicker
_dateDisplay = FindViewById<TextView>(Resource.Id.date_display);
_dateSelectedButton = FindViewById<Button>(Resource.Id.date_select_button);
_dateSelectedButton.Click += DateSelected_OnClick;
//End DatePicker
}
void DateSelected_OnClick(object sender, EventArgs e)
{
DatePickerFragment frag = new DatePickerFragment.NewInstance(delegate (DateTime time)
{
_dateDisplay.Text = time.ToLongDateString();
});
frag.Show(FragmentManager, DatePickerFragment.TAG);
}
}
おかげアーウィンは、私はそれを行って気付きませんでした。許可されると5分後に回答とマークされます。 –