Monodroid OnDismiss与对话片段

时间:2013-04-09 05:14:40

标签: c# xamarin.android android-dialogfragment

我有一个自定义DialogFragment,它来自使用ListView的片段活动。

在API 14中,它运行正常。

但是,在API 8中,在片段中按下“保存”按钮后会抛出以下错误,并返回主活动。

“java.lang.IllegalStateException:适配器的内容已更改,但ListView未收到通知。请确保不从后台线程修改适配器的内容,而只是从UI线程修改。 [在ListView(2131099672,类android.widget.ListView)中使用Adapter(class timepilot.EmployeesAdapter)]“

我可以在父活动中编写一个NotifyDataSetChanged()方法,只需调用Update()并在按下保存时和NotfiyDataSetChange()之前在片段中调用它,并且可以使用很好,但感觉这是一种不那么正确的方式。

无论如何使用monodroid为Dialog Fragment实现OnDimissListener? (我已经看到许多使用android做这个的例子,但无法用monodroid来解决它。)

更奇怪的是,API 14中没有抛出此错误,只是在API 8中。

EmployeeActivity.cs

Dismiss()

UserProfileFragment.cs

{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set up Listview
        SetContentView(Resource.Layout.EmployeeMaster);
        employeesAdapter = new EmployeesAdapter(this);
        listView = FindViewById<ListView>(Resource.Id.employees);
        listView.Adapter = employeesAdapter;

        // Dedicate Buttons
        this.FindViewById<Button>(Resource.Id.button_edit).Click += EditButton_Click;
        this.FindViewById<Button>(Resource.Id.button_add).Click += AddButton_Click;
        this.FindViewById<Button>(Resource.Id.button_settings).Click += SettingsButton_Click;

        // Gestures
        gestureDetector = new GestureDetector(this);
        listView.SetOnTouchListener(this);

        var x = employeesAdapter.Count;
    }

void AddButton_Click(object sender, EventArgs e)
    {
        FragmentTransaction trans = this.SupportFragmentManager.BeginTransaction();
        UserProfileFragment userProfileDialog = new UserProfileFragment();
        userProfileDialog.Show(trans, "profile");          
    }
}
...

0 个答案:

没有答案
相关问题