如何控制的ListView与MVP模式为Android [英] How to control ListView with MVP Pattern for Android

查看:420
本文介绍了如何控制的ListView与MVP模式为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发使用MVP模式的Andr​​oid应用程序。

I'm currently developing an android app using MVP Pattern.

当我尝试开发一个活动,我应该使用一个ListView。所以我使用适配器的ListView。不过听说适配器是类似于在MVP模式presenter。

When I try to develop an Activity, I should use a ListView. So I'm using Adapter for ListView. But I heard Adapter is similar to Presenter on MVP Pattern.

我想,如果Apdater是smiliar至presenter,那么我应该做presenter更新,而不是适配器的ListView。

I think if Apdater is smiliar to Presenter, then I should make Presenter for updating ListView instead of Adapter.

在这种形势下,如何发展的ListView?只需使用适配器并继续使用MVP模式?

When this situation, how to develop ListView? Just use Adapter and keep using MVP Pattern?

感谢您的阅读。

推荐答案

是的,适配器应该在MVP模式的P成分。事实上列表视图得多写成MVP-的getView()函数需要来设置它的每一个调用时视图的所有值pretty,这是一个什么样的presenter必须做的差不多的定义。虽然它也很容易使用它在MVC型方式 - 只需上它传递模型和做的意见,即工作视图getView通话功能。因此,其实无论哪种方式都可以工作,只挑选自己preference。

Yes, the Adapter should be the P component in an MVP pattern. In fact ListViews are pretty much written as MVP- the getView() function needs to set all the values of the view each time its called, that's almost the definition of what a presenter must do. Although it's also easy to use it in an MVC type way- simply have getView call functions on the View that pass it the model and do that work in the Views. So really either way will work, just pick your preference.

如果你使用复杂的列表行的MVP模式,我喜欢交行定制的复合视图,并把更多的描述函数名上它 - 这样,而不是去listRow.findViewById(R.id.textView).setText (文件名)我会去listRow.setFilename(文件名),并让视图知道如何处理这一点。那种模糊MVP和MVC一点的界限,但我觉得你的适配器的可读性很好的平衡,避免一些尴尬的纯MVC有时也带来了。

If you do use an MVP model with complex list rows, I like to make the rows a custom compound View and put more descriptive function names on it- so rather than going listRow.findViewById(R.id.textView).setText(filename) I'll go listRow.setFilename(filename) and let the view know what to do with that. That kind of blurs the bounds of MVP and MVC a bit, but I find it a good balance of readability of your adapter and avoiding some of the awkwardness pure MVC sometimes brings.

这篇关于如何控制的ListView与MVP模式为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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