I pretty stumped on how to refresh a ListAdapter I have in an activity from an AlertDialog I'm calling from the same activity.
Here's the code of the activity:
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);
}
}
And this is my AlertDialog:
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();
}
}
Shown in the AlertDialog code above, my datasouce get updated with no problems and when I call the NotifyDataSetChanged
method nothing happens.