简体   繁体   English

如何将Android源代码整理到文件夹中

[英]How to organize Android source code into folders

I'm working on an Android app and it's up to 17 classes. 我正在开发一个Android应用程序,它最多可以上17个课程。 I want to start organizing the .java class files into a more intuitive layout. 我想开始将.java类文件组织成更直观的布局。

Say I want to have a source code directory called "views". 假设我想要一个名为“views”的源代码目录。 When I create that directory using Eclipse, it changes my package name to com.xyz to com.xyz.views. 当我使用Eclipse创建该目录时,它将我的包名称更改为com.xyz到com.xyz.views。

Since this package name (com.xyz.views) is different than the rest of my app (com.xyz) is this going to cause me to do a lot of extra work to link those packages? 由于这个包名称(com.xyz.views)与我的应用程序的其余部分(com.xyz)不同,这是否会导致我做很多额外的工作来链接这些包? Will this cause problems with the fact that Android Market looks at the package name and is more or less locked to the package name? 这会导致Android Market查看软件包名称并且或多或少地锁定到软件包名称这一事实会导致问题吗?

I'm organizing my app src in different subfolders. 我在不同的子文件夹中组织我的应用程序src。 There's no problem with it. 它没有问题。

is this going to cause me to do a lot of extra work to link those packages 这会导致我做很多额外的工作来链接这些包

Isn't that what a smart IDE would do when you refactor the classes via the 'refactor' context menu? 当你通过'refactor'上下文菜单重构类时,这不是智能IDE会做的吗? At least Eclipse and IntelliJ should do that. 至少Eclipse和IntelliJ应该这样做。

In my manifest, I have 在我的清单中,我有

<manifest package="com.myapp.android"

while my activities for example (in your case would be 'views') are referenced as: 而我的活动例如(在你的情况下是'views')被引用为:

<activity android:name=".activity.main.Splash"

Works fine for me. 对我来说很好。

So, part of my folder structure is for example 因此,我的文件夹结构的一部分是例如

com/myapp/android/
com/myapp/android/activity
com/myapp/android/util
com/myapp/android/model

Java works like that, it uses separate files for separate public classes and folders for packages. Java就是这样的,它为单独的公共类使用单独的文件,为包使用文件夹。 If you want a source folder, you will also get a corresponding Java package. 如果您需要源文件夹,您还将获得相应的Java包。 A smart IDE should take care of the imports and references for you. 智能IDE应该为您处理导入和引用。

Subpackages should be handled by Android just fine, don't worry about that. 分组应该由Android处理好,不用担心。

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

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