简体   繁体   English

我在Android中的MVP模式方法

[英]My MVP pattern approach in android

I am trying to implement MVP in my android project. 我正在尝试在我的android项目中实现MVP。 I have the view which is basically my activity. 我认为这基本上是我的活动。 which I am trying to make basically a dumb view so It calls my presenter to do all of its work. 我基本上想使自己的观点变得愚蠢,因此它要求主持人完成所有工作。

I have a presenter class, which acts as an intermediary between the model and the View and finally the model Which I use to retrieve and save the data that needs to be represented in the view and is passed back via the presenter. 我有一个presenter类,它充当模型和视图之间的中介,最后充当我用来检索和保存需要在视图中表示并通过presenter传递回的数据的模型。 I hope this is correct so far? 我希望到目前为止这是正确的吗?

Basically I want to create and Gridlayout of Image buttons in my Mainactivity(view). 基本上我想在Mainactivity(view)中创建Image按钮的GridLayout和Gridlayout。 These image buttons will basically be thumbnails from a folder on the phone. 这些图像按钮基本上是手机上文件夹中的缩略图。 So basically my model will parse a folder and return Images to my view. 因此,基本上我的模型将解析一个文件夹并将图像返回到我的视图。 my question is should Iterate over the images in the View as the View is meant to be dumb? 我的问题是,因为视图本来就愚蠢,所以应该遍历视图中的图像吗? I feel it shouldn't although on the other hand this is essentially UI logic, as it is creating a view and only dealing with a bunch of UI elements (Images).Any help is appreciated. 我觉得不应该这样做,尽管从另一方面讲,这本质上是UI逻辑,因为它正在创建视图并且仅处理一堆UI元素(图像)。

Your view has not to be completely Dumb. 您的观点不一定完全是哑巴。

It should know how to present the data to the user and interact with him/her. 它应该知道如何将数据呈现给用户并与他/她互动。

In your case, you could have a view taking a lot of images and showing them as thumbnails for phones and handling touch screen features, while another view that would display differently on computer screen for example and be specific to mouse gesture. 在您的情况下,您可能有一个视图,它拍摄大量图像并将其显示为电话的缩略图并处理触摸屏功能,而另一个视图在计算机屏幕上的显示方式会有所不同,例如鼠标手势。

You could keep for both the same model/presenter. 您可以保留相同的模型/演示者。

On a side note, I'm relatively new to Android development and I'm not sure if MVP is usually used in Android dev. 附带说明一下,我是Android开发的新手,我不确定MVP是否通常在Android开发人员中使用。


Here is a question which was asked about MVP being useful or not for Android dev : https://softwareengineering.stackexchange.com/questions/133134/is-model-view-presenter-mvp-scheme-useful-for-android 这是一个关于MVP是否对Android开发人员有用的问题: https : //softwareengineering.stackexchange.com/questions/133134/is-model-view-presenter-mvp-scheme-useful-for-android

Another here : Comments on my MVP pattern for Android 另一个在这里: 对我的Android MVP模式的评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM