我很困惑如何刷新我在从同一个活动中调用的 AlertDialog 的活动中的 ListAdapter。
这是活动的代码:
private static ArrayAdapter<CarProfile> mainListAdapter;
public class CarProfiles : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
mainListAdapter = new ArrayAdapter<CarProfile>(this, Android.Resource.Layout.SimpleListItem1, carProfiles);
// This targets a ListView in my axml with id list.
ListAdapter = mainListAdapter;
ShowCarProfileFormDialog(parameters blah, blah, blah);
}
}
这是我的警报对话框:
public class CarProfileDialogFragment : DialogFragment
{
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
LayoutInflater inflater = Activity.LayoutInflater;
View view = inflater.Inflate(Resource.Layout.CarProfileForm, null);
// component init (removed)
var builder = new AlertDialog.Builder(Activity)
.SetView(view)
.SetPositiveButton(GetString(Resource.String.lblCarProfileDialogOK), (sender, args) =>
{
// The datasouce source update works
datasource.UpdateCarProfile(id, txtName.Text, txtPlateNumber.Text, spnCategoryColor.SelectedItem.ToString(), spnCategoryNumber.SelectedItem.ToString());
// But this doesn't
mainListAdapter.NotifyDataSetChanged();
})
.SetNegativeButton(GetString(Resource.String.lblCarProfileDialogCancel), (sender, args) =>
{
Dialog.Dismiss();
})
.SetTitle(GetString(Resource.String.lblCarProfileDialogTitle));
return builder.Create();
}
}
如上面的 AlertDialog 代码所示,我的数据源更新没有问题,当我调用该NotifyDataSetChanged
方法时没有任何反应。