Refresh Fragment from AlertDialog

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.


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

FragmentManager fm = getSupportFragmentManager();
MyDialog d = new MyDialog();
d.setDataChangeListener(this);
d.show(fm, "fragment_name");

In your case I would pass the Adapter instance to the class, which creates the Dialog. I don't see there any other solution.

You can also create the Dialog in the Fragment class and define the OnClickListener as inner class, so you can directly access the Adapter.

You can also use something like an event bus, which helps a lot for louse coupling.

链接地址: http://www.djcxy.com/p/64592.html

上一篇: 多下载与ListView Asynctask

下一篇: 从AlertDialog中刷新片段