我正在使用Xamarin Android开展项目。在我的活动中,我有一个按钮的列表视图:
当我点击其中一个按钮时,会出现一个DatePickerDialog:
我想知道的是,点击肯定按钮(保存按钮)后,是否有办法在DatePickerDialog下刷新活动
以下是DIALOG
下方保存按钮的代码 private async void HandlePositiveButton(object sender, DialogClickEventArgs e)
{
var dialog = (AlertDialog)sender;
DateTime currentDate = Convert.ToDateTime(DateTextView.Text);
DateTime changedDateTime = currentDate.Add(TimeSpan.Parse(Vm.CurrentTime));
Vm.CurrentDateTime = changedDateTime;
var success = await Vm.UpdateTimeLog();
}
我想在Listview按钮的活动中做什么我想为下面的listview适配器调用我的代码:
Vm.ShowCurrentUser();
buttonCollection = await Vm.ShowButtons();
if (buttonCollection.Count > 0)
{
listAdapter = new CustomButtonAdapter(this, buttonCollection);
ButtonListview.Adapter = listAdapter;
}
我已经尝试过onPause和OnResume,但点击了Save按钮后没有调用,并且对话框被解除。
baseadapter下面按钮的clickevent代码:
public async void OnClick(Android.Views.View v)
{
Task<string> asyncClock = Vm.ClockCommand();
string results = await asyncClock;
var dialog = ChangeDateTimeDialogFragment.NewInstance();
dialog.Show(this.activity.FragmentManager, "dialog");
}
我已尝试在以下按钮的点击事件中执行以下代码:
activity.Finish();
activity.StartActivity(context.Intent);
不幸的是,这会消除对话框的显示。
答案 0 :(得分:1)
所以我意识到我已经拥有驻留在自定义基本适配器中的父活动,用于具有按钮列表视图的父活动。因此,在基本适配器的自定义按钮的Click事件中,我只需执行以下操作,它就更新了按钮列表视图!
private class ButtonClickListener : Java.Lang.Object, Android.Views.View.IOnClickListener
{
private Activity activity;
private ObservableCollection<UserButtonLabel> buttonCollection = new ObservableCollection<UserButtonLabel>();
private CustomButtonAdapter listAdapter;
public ButtonClickListener(Activity activity)
{
this.activity = activity;
}
public async void OnClick(Android.Views.View v)
{
ListView ButtonListview = activity.FindViewById<ListView>(Resource.Id.ButtonListview);
string name = (string)v.Tag;
string text = string.Format("{0} Button Click.", name);
Toast.MakeText(this.activity, text, ToastLength.Short).Show();
Task<string> asyncClock = Vm.ClockCommand();
string results = await asyncClock;
var dialog = ChangeDateTimeDialogFragment.NewInstance();
dialog.Show(this.activity.FragmentManager, "dialog");
Vm.ShowCurrentUser();
buttonCollection = await Vm.ShowButtons();
if (buttonCollection.Count > 0)
{
listAdapter = new CustomButtonAdapter(activity, buttonCollection);
ButtonListview.Adapter = listAdapter;
((BaseAdapter)this.listAdapter).NotifyDataSetChanged();
}
}
}
private static UserTimeTrackingViewModel Vm
{
get
{
return App.Locator.UserTimeTracker;
}
}
}
此Button Listener是一个私有类,无论如何都驻留在Custom BaseAdapter中。