How to organize Android source code into folders
I'm working on an Android app and it's up to 17 classes. I want to st开发者_StackOverflowart organizing the .java class files into a more intuitive layout.
Say I want to have a source code directory called "views". When I create that directory using Eclipse, it changes my package name to com.xyz to 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? 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?
I'm organizing my app src in different subfolders. 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? At least Eclipse and IntelliJ should do that.
In my manifest, I have
<manifest package="com.myapp.android"
while my activities for example (in your case would be 'views') are referenced as:
<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. If you want a source folder, you will also get a corresponding Java package. A smart IDE should take care of the imports and references for you.
Subpackages should be handled by Android just fine, don't worry about that.
精彩评论