I am new at Android development and also Java. I am working on a project, which is of medium size.
I am wondering how one can organize the code best. Right now I have too many classes, so I use the file find too much to find things.
I have read that it is not possible to store e.g. icons under specific sub folders. I did not find a way to do this with classes either. Is it not possible to add a folder and then maybe extend the namespace to my.project.com.foldername?
I have lots of classes, which I would like to group. E.g. I would lige to group classes of type database, layout etc together in folders. If I create a new package I can not access the public classes easily. Or am I missing something.
And is there something like sections or regions, to group the code within a class? I would like to collapse the code and expand to see regions, or how it may be called in Java. Similar to the description of a method. But I would like to put e.g. 5 public method in a region public. So I will quickly find it, if I know that they are public for instance.
Please remember, I am new to Java and Android. So I may miss an obvios point.
Best Regards,
Patrick
The correct way will be to use packages. Group your classes like this:
For each package you create a new folder. Eclipse will do that automatically for you. To use a public method from a class from a different package, you need to import it:
Again Eclipse is your friend. Type Ctrl+Shift+O (Right Click, Source, Organize imports) to add the declaration automatically.
Eclipse’s editor doesn’t support collapsing just the public or private methods. But you could use the Outline to navigate between methods. Public methods are denoted with green circles, private with red squares. Keep your classes small and you shouldn’t have a problem navigating through the code.