If you develop apps for Android you may have noticed, that you quickly lose the overview of your layouts, ids, drawables, packages, etc. I want to share my experience with you and suggest a few tips, how to organize your projects. I consider myself to these rules, because they help me (and of course others) a lot to know about the project. If you work as a team it is even more important to define rules for the naming and the organization of the project.

  • The res folder
  • Packaging
  • Separating paid & free version

The res folder

I'm always trying to write as much as possible in XML and not in Java, so the resources folder can contain a lot of files. There are layouts, menus, strings, etc. If you have a lot of layouts you'll have a lot more ids.

Naming of layouts

  • activity_dashboard.xml
  • activity_profile_list.xml
  • activity_map.xml
  • dialog_about.xml
  • dialog_eula.xml
  • list_item_profile.xml
  • list_item_setting.xml
I always put the name which the XML is used for, in front of the actual name. You can also use abbreviations, if you prefer them.
  • a_dashboard.xml
  • d_about.xml
  • li_profile.xml

Naming of Ids

I advise you to give only those widgets an id, that you'll need in your code. So mostly you can remove the id-attribute of layouts and scrollviews. To keep the overview over your ids, I suggest to put the layout name and the widget name in front of the id name. <layout>_<widget>_name
  • activity_dashboard_btn_profile or a_dashboard_btn_profile
  • d_about_ibtn_info
  • li_profile_tv_name

Widget names

  • Button = btn
  • ImageButton = ibtn
  • EditText = et
  • TextView = tv
  • ImageView = iv
  • ...

Separation in the values ​​folder

I really³ advise you to use styles and themes. It's a simple way to give your app a unique look. In my last project i end up with the following files. The biggest advantage is, that you can define different values for different screen sizes, languages, etc. .
  • strings.xml
  • themes.xml
  • styles.xml
  • colors.xml
  • ids.xml
  • attrs.xml
  • dimens.xml
strings.xml: for every string, which is used in a layout or get displayed
themes.xml: is basically a style which sets general attributes to an whole application
styles.xml: for every customization for your widgets i.e. TextViews, Buttons, ...
colors.xml: I used it to define some general colors for text and showdow colors, Actionbar background and stuff like that
ids.xml: you only use this if you want to use an id in more layouts
attrs.xml: for custom attributes in custom styles
dimens.xml: I used it to set the height of the actionbar, text size (small, medium, large), padding, ...
Extra info!!
As mentioned previously the advantage is to separate screen sizes with qualifier names. You can have a dimens.xml file in the standard values folder and some different values in the values-xlarge (for tablets).
With the strings.xml you can provide support for multilingualism.
values (default:English), values-de, values-fr, ...

Naming of drawables

This is similar to layouts and ids.
ac = actionbar, ic = icon, bgr = background


I also recommend to write your menus in XML. You can separate phone and tablet(actionbar) menus with the folders menu for phones and menu-v11 for Honeycomb tablets.
I put "menu_" in front of the file name. And the ids again with menu_dashboard_info (Note: i name the menu and the layout the same)


This chapter is also very important. I think most of you know how to use and name packages useful, but I've seen a lot of projects were all classes are stuffed in one packet. So here are some suggestions For the main package take your website's url and reverse it or your company name: <country code>.<company name>.<project name> Examples:
  • com.yourcompany.awesomeapp
  • at.bartinger.smartphone
And examples for the sub packages:
  • at.bartinger.smartphone
    • activity
      • widget
        • adapter (list adapters)
        • map (map overlays)
    • dialog
    • receiver
    • service
    • sql (SQLite stuff)
    • util (General classes like Helpers, etc.)

Separating paid & free version

You want to sell an app in the Android Market, but also want to provide a free demo. It would be annoying if you always have to edit the code in to projects. The solution to that is called "Library project". Create a new project and extend the package name with ".library". Add "public static boolean isFreeVersion=true;" to your main activity and develop your app as usual. Use this boolean if you want to block something in the free version. If you're done create 2 new projects one for the full and one for the free version. The package names could look like this:
  • Lib: at.bartinger.smartphone.library
  • Full: at.bartinger.smartphone
  • Free at.bartinger.smartphone.free
Then go to its properties (Right click on the project > Properties > Android), scroll down and check the "Is Library" box. In your full and free version go the the properties too and press Add... to add the library. In the full version add the Market Licensing Check and set the isFreeVersion to false. Great tut here. The free version just starts an activity with starts the main activity of the library. Now if you have to change something in your app you just have to update the library project, export the full and free version and upload it again.
That's it for now. Note that you don't have to follow these rules. These are just a few guidelines which I consider myself to make my projects scale-able without loosing the overview. I continue writing on this post if I ever come up with new things and if you know some important rules which you follow let me know in the comments below.
Thanks for reading.