简体   繁体   English

在Android中将UI与Logic分开

[英]Separate UI from Logic in Android

I recently read a blog post by the Gmail team on the approach they used to develop the different platform versions for Inbox for Gmail. 最近,我阅读了Gmail团队的博客文章 ,内容涉及他们用来为Inbox for Gmail开发不同平台版本的方法。 The short story is that they write everything in Java (so basically for Android) but separate all the UI code from the shared logic code. 简而言之,他们用Java编写了所有内容(基本上是Android),但是将所有UI代码与共享逻辑代码分开了。 Then for iOS they reimplement the UI in a platform specific iOS manner but use a program they developed (and open sourced) called J2ObjC to convert the shared logic from Java to Objective C. 然后,对于iOS,他们以特定于平台的iOS方式重新实现UI,但使用他们开发(并开源)的名为J2ObjC的程序将共享逻辑从Java转换为ObjectiveC。

I understand how to get this working on the iOS but how should I arrange the classes on the Android? 我了解如何在iOS上使用此功能,但如何在Android上安排课程? I understand that I need to create separate classes for the different parts of the shared logic but how do I this practically so that a) all the shared logic is in its own directory so I can easily reference it on it's own and b) I can still reference it from my activities. 我了解我需要为共享逻辑的不同部分创建单独的类,但是实际上我该如何做,以便a)所有共享逻辑都在其自己的目录中,这样我就可以轻松地单独引用它,并且b)我可以仍然从我的活动中引用它。

Based on my searches I think I need to use the MVP pattern but I'm not 100% sure. 根据我的搜索,我认为我需要使用MVP模式,但不确定100%。

I put the model logic in a separate project with no Android dependencies. 我将模型逻辑放在没有Android依赖项的单独项目中。 Another project depends on the shared project and contains the user interface and builds the Android project. 另一个项目取决于共享项目,并包含用户界面并构建Android项目。

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

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