更新基于异步任务结果的ListFragment

编程入门 行业动态 更新时间:2024-10-24 21:28:23
本文介绍了更新基于异步任务结果的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

本文发布于:2023-11-15 00:36:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1589566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ListFragment

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!