问题描述
是否可以在android中实现Java中的Model -view -controller模式?
还是已经通过活动实施?还是有更好的方法来实现Android的MVC模式?
推荐答案
在Android中,您没有MVC,但是您有以下内容:
- 您定义用户界面在各种XML文件中,按分辨率,划分,硬件等
- 您定义 resources 等等
- 您扩展了诸如 listActivity , tabActivity 并使用充气器.
- 您可以根据自己的业务逻辑创建尽可能多的类.
- 很多 utils - 数据库,html.
其他推荐答案
没有普遍唯一的MVC模式. MVC是一个概念,而不是坚实的编程框架.您可以在任何平台上实现自己的MVC.只要您坚持以下基本思想,就可以实现MVC:
- 模型:渲染内容
- 视图:如何渲染
- 控制器:事件,用户输入
也这样考虑:编程模型时,模型不必担心渲染(或平台特定代码).该模型会对视图说,我不在乎您的渲染是Android还是iOS或Windows Phone,这是我需要您渲染的内容. 该视图仅处理特定于平台的渲染代码.
当您使用 mono 时,这特别有用.开发跨平台应用程序.
其他推荐答案
Android上的动作,视图和活动是与Android UI合作的烘焙方式,并且是 model-view – View-viewModel(MVVM)模式的实现,该模型 在结构上相似(在同一家族中与模型 - 视图 - 控制器.
据我所知,没有办法突破这种模型.它可能可以做到,但是您可能会失去现有模型所拥有的所有好处,并且必须重写自己的UI层以使其正常工作.
问题描述
Is it possible to implement the model–view–controller pattern in Java for Android?
Or is it already implemented through Activities? Or is there a better way to implement the MVC pattern for Android?
推荐答案
In Android you don't have MVC, but you have the following:
- You define your user interface in various XML files by resolution, hardware, etc.
- You define your resources in various XML files by locale, etc.
- You extend clases like ListActivity, TabActivity and make use of the XML file by inflaters.
- You can create as many classes as you wish for your business logic.
- A lot of Utils have been already written for you - DatabaseUtils, Html.
其他推荐答案
There is no universally unique MVC pattern. MVC is a concept rather than a solid programming framework. You can implement your own MVC on any platform. As long as you stick to the following basic idea, you are implementing MVC:
- Model: What to render
- View: How to render
- Controller: Events, user input
Also think about it this way: When you program your model, the model should not need to worry about the rendering (or platform specific code). The model would say to the view, I don't care if your rendering is Android or iOS or Windows Phone, this is what I need you to render. The view would only handle the platform-specific rendering code.
This is particularly useful when you use Mono to share the model in order to develop cross-platform applications.
其他推荐答案
The actions, views and activities on Android are the baked-in way of working with the Android UI and are an implementation of the model–view–viewmodel (MVVM) pattern, which is structurally similar (in the same family as) model–view–controller.
To the best of my knowledge, there is no way to break out of this model. It can probably be done, but you would likely lose all the benefit that the existing model has and have to rewrite your own UI layer to make it work.