0

I have a Fragment with a ListView on it. This ListView is filled with an adapter.

I start a DialogFragment an there I can type in the data for a now row on the ListView.

Now I want to refresh the Fragment under the Dialog when the Dialog is closed.

How can I refresh the ListView? I can't call the notifyDataSetChanged() from outside the fragment.

I read something about a callback loader, but I populate the ListView with an array. As far as I understand the callback Loader i have to use a Cursor for that.

I also tried to call a function of the activity but then i couldn't call the notifyDataSetChanged() too. To make the Adapter static didn't work.

I Hope someone understands my Problem and can halp to fix it.

4

2 回答 2

1

在您的情况下,我会将适配器实例传递给创建对话框的类。我没有看到任何其他解决方案。

您也可以在 Fragment 类中创建 Dialog,并将 OnClickListener 定义为内部类,这样就可以直接访问 Adapter。

您还可以使用事件总线之类的东西,这对虱子耦合有很大帮助。

于 2013-06-05T19:49:09.670 回答
0

您可以将调用片段设置为侦听器。

FragmentManager fm = getSupportFragmentManager();
MyDialog d = new MyDialog();
d.setDataChangeListener(this);
d.show(fm, "fragment_name");
于 2013-06-05T19:50:02.257 回答