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

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


The device will not complain if you use camel-case id names. For my first application I wrote all the ids in camel-case because I think it appears better in the Java code that way, and it works just fine.

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

// This must be undescored due to naming constrictionssetContentView(R.layout.my_long_layout_name);// Now this looks a little out of placefindViewById(R.id.myLongSpecificId);

I, too, wonder about the standards here. Google is inconsistent in their examples; sometimes they use all lowercase, sometimes they insert underscores, and sometimes they use camel-case.


If you take look at android.R.id.* fields, you will notice that all of them are in camel-case. So if the android ids are written in camel-case, I guess we have to follow this convention :)


i think it is good if we use the all small letters with underscores.

Just look at this(Adding to what Daniel had answered)

  // Camel Case    TextView tvUserName = (TextView) findViewById(R.id.tvUserName);
    // Small Caps and Underscores    TextView tvUserName = (TextView) findViewById(R.id.tv_user_name);

in my own experience I tend to get a little confused of the camel case convention in xml because when you link it to Java which also uses camel case(because it is the standard) it looks like a doppleganger.