在不同的ListView与适配器不同的数据共用后更新 [英] Update common post in different ListView with different data in adapter

查看:94
本文介绍了在不同的ListView与适配器不同的数据共用后更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个应用程序,首先列出所有岗位在的ListView 片段第1 )与自定义适配器。和自定义适配器的数据是的ArrayList<哈希映射<字符串,字符串>>

Assume That an app Firstly List all post in a ListView in Fragment ( 1st ) with a custom adapter. and that custom adapter data is ArrayList<Hashmap<String,String>>

然后用户可以像类片段的另一个片段( 2日),我们有另外的ListView不同的数据。 我们使用回栈片段和用户可以通过单击后退按钮返回到$ P $光伏片段。

Then users can go to another fragments like category fragment ( 2nd ), that we have another listview with different data. We using back stack for fragments and user can back to prev fragment by clicking back button.

问题:

Issue:

在这些碎片一些后可以通用!像图像连接,在第一幅图像,我们可以看到所有的邮册后,当在类别点击并进入类的片段,我们可以再次看到那个帖子。

in these fragments some post can be common! Like image attached, in first image, we can see a post in all post List, and when click on category and goes to category fragment, we can see that post again.

那么,如果在这个职位用户点击并进入单发布活动( 3 ),用户可以看到类似按钮,可以喜欢这个岗位( 4 )。

Then if user click on this post and goes to single post activity ( 3rd ), user can see like button and can like this post ( 4th ).

到现在为止的每一件事情就OK! 但麻烦的是发生在用户单击后退按钮!第一个用户去类别片段( 5 ),我们应该表现出像列表查看方式喜欢按钮按钮。 如果用户进一步回转到所有文章中,我们想在列表视图按钮,喜欢过! ( 6

Until now every thing is OK! But trouble is happen when user click back button! first user goes to category fragment ( 5th ) and we should show like button on List View as liked button. And if user goes further and back to all post we should like button in that list view as liked too!! ( 6th )

什么是处理这个问题的最佳策略是什么? :)

what's the best strategy to handle this issue? :)

推荐答案

您可以创建数据绑定的模式,您的列表视图,并填充列表视图的数据。

You can create the model of the data bind to your list view and populate the list view with that data.

要具有后执行的东西像制作像按钮,你可以使用广播接收器(本地),也可以使用 tinyBus 或奥托有回调的任何类型的事件。

To have post execution of something like making like button you can use broadcast receiver(local) or can use tinyBus or otto to have call backs for any kind of event.

在获得回调只是通知片段的具体名单。

After getting the callback just notify the particular list in fragments.

诀窍在于模式的形成和回调之间。

Trick lies between model formation and callbacks.

这篇关于在不同的ListView与适配器不同的数据共用后更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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