更新基于异步任务结果的ListFragment [英] Updating a ListFragment based on Async Task result

查看:210
本文介绍了更新基于异步任务结果的ListFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景:
我有这显示好友列表清单片段。当一个列表项pressed,我展示了对话片段朋友的详细信息。

Scenario : I am having a list fragment which displays a list of friends. When an list item is pressed, I'm showing the details of the friend in a dialog fragment.

问题:
在该对话框中的片段,我有一个选项,从我的好友列表中删除好友(在远程服务器上)。我使用异步粘性来执行此。从对话片段回来后,我应该如何更新旧的好友列表。 如何我触发片段刷新。由于异步任务不知道自定义列表适配器列表中的片段被使用。

Problem: In the dialog fragment, I'm having an option to delete the friend from my friend list (in a remote server) . I'm using Async tack to perform this. After returning from the dialog fragment, how should I update the 'old' friend list. How do I trigger a fragment 'reload'. Since the async task is not aware of the custom list adapter being used in the list fragment.

对不起,我会尽快加code。如果有人见过该方案之前,请提供您的建议。

Sorry, I will add the code ASAP. If anyone have met this scenario before kindly provide your suggestions.

编辑:删除成功从好友列表的朋友在远程服务器之后,我想重装显示在列表中的片段列表。有触发列表中的片段本身dataSetChanged通知的方式。

After successfully deleting a friend from the friend list in a remote server, I want to reload the list being displayed in the list fragment. Is there a way to trigger the dataSetChanged notification in the list fragment itself.

推荐答案

没有问题。我猜 ListFragment 是从一些数据源读取 - 无论是一个 ArrayAdapter SimpleCursorAdapter (或类似的东西) - 你的任务也修改源代码。当的AsyncTask 完成后,你应该能够得到的片段和更新基础数据。例如:

No problem. I'm guessing the ListFragment is reading from some data source - be it an ArrayAdapter or a SimpleCursorAdapter (or something similar) - and your task is also modifying that source. When the AsyncTask finishes, you should just be able to get that fragment and update the underlying data. For example:

// ...
void onPostExecute(Void result) {
    ListFragment lFrag = (ListFragment) getFragmentManager().findFragmentById(R.id.yourListFragment);
    BaseAdapter adapter = (BaseAdapter) lFrag.getListAdapter();
    adapter.notifyDataSetChanged();
}

这篇关于更新基于异步任务结果的ListFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆