Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are Android layout file names so limited?

It's good to have consistency in file names.

MyActivity.java contains the public class MyActivity

I would like the xml file with its layout to be called res/layout/MyActivity.xml

But I get an error message saying "Invalid file name: must contain only [a-z0-9_.]"

So two questions:

  1. Why is the character set so limited (not even upper case? Come on!) - Ah - this restriction is probably in place so you will never be screwed by filesystems that don't make a distinction between upper and lower case, like Apple's HFS+ (although see Wikipedia for the gory story http://en.wikipedia.org/wiki/Comparison_of_file_systems#cite_note-note-35-77 )

  2. Which filenames are restricted - all of res? just res/layout? res/layout plus some other folders?

Can anyone confirm 1, and give details on 2?

Thanks,

Peter

like image 759
Peter vdL Avatar asked Jun 24 '10 22:06

Peter vdL


2 Answers

Why is the character set so limited

Because the name has to be a valid Java identifier, so you can use constants like R.layout.foo to identify the layout at runtime.

Which filenames are restricted - all of res? just res/layout? res/layout plus some other folders?

Anything in res/

like image 72
CommonsWare Avatar answered Oct 13 '22 19:10

CommonsWare


Not sure of the reason for #1. Never seen an explanation in any readings about Resources. For #2 from my experience anything that will be used as a id in java e.g., R.drawable.marker, R.string.default_message has to follow those rules of [a-z0-9_].

like image 2
Robby Pond Avatar answered Oct 13 '22 19:10

Robby Pond