Are there conventions on how to name resources?

Eugene picture Eugene · Aug 23, 2011 · Viewed 45k times · Source

Are there conventions how to name resources in Android? For example, buttons, textViews, menus, etc.

Answer

Samuel picture Samuel · Aug 29, 2011

Android SDK will be a good place to start.

For example, I try to scope IDs within the activity.

If I had a ListView it simply would be @android:id/list in all the activities.
If, however, I had two lists then I would use the more specific @id/list_apple and @id/list_orange

So generic (ids, ...) gets reused in the R.java file while the unique ones (sometimes gets reused) get prefixed with generic ones separated by an underscore.


The underscore is one thing, I observed, for example:

Layout width is layout_width in xml and layoutWidth in code, so I try to stick to it as list_apple

So a Login button will be login, but if we have two logins then login_foo and login_bar.