Thursday 15 April 2010

mobile - Android id naming convention: lower case with underscore vs. camel case -


I'm currently programming an application for Android. Now what I have found is that you can not add resource items, say, an image in the docs folder and name it like "myTestImage.jpg". This will give you a compiler error because the camel case syntax is not allowed, so you have to give it a name like "my_test_image.jpg".

But in the XML file you define, say that you have the following definition

  & lt; TextView Android: id = "@ + id / myTextViewFirstname" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Firstname" / & gt;  

This is a valid definition, compile and works fine on my Android emulator - however as you see - I am specifying IDs in camel case syntax.

Now, Android samples always use lower case and underscores. Is this just a naming convention that uses a short case with an underscore for the ID or can it cause problems on the actual device?

Thx

if you use camel-case ID names I will not complain for my first application I have written all the ids in the case of camel because I think it is better in Java code, and it works fine.

I am gradually changing my mind on the camel-case, however, because you end up with two different naming conventions - for example:

  // Naming constrictions due to setContentView (R.layout.my_long_layout_name) it should be undescored; // Now it looks a bit out of place ViewById (R.id.myLongSpecificId);  

I also think about the standards here. Google is incompatible with their examples; Sometimes they use all lowercase, sometimes they put underscores, and sometimes they use camel-case.


No comments:

Post a Comment