Are there conventions how to name resources in Android? For example, buttons, textViews, menus, etc.
In deciding what resources are within your system, name them as nouns as opposed to verbs or actions. In other words, a RESTful URI should refer to a resource that is a thing instead of referring to an action. Nouns have properties as verbs do not, just another distinguishing factor.
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.
Project lead's last name or initials. File creator's last name or initials. Project name/acronym.
In resource-oriented APIs, resources are named entities, and resource names are their identifiers. Each resource must have its own unique resource name. The resource name is made up of the ID of the resource itself, the IDs of any parent resources, and its API service name.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With