How do you name UI elements?
I have been trying to find an answer to开发者_开发技巧 this question for months, but even Android documentation directs to Java naming convention document which does not say anything (which is logical) about Android-specific elements like TextView, EditView, etc. It also seems that stackoverflow does not have an answer to this question. Not to mention that Google demo projects use kindergarten namings, like myButton, yourEditView, theirTextView, etc. :)
So what document do you use as a source for Android-element naming convention? We've tried developing our own naming conventions, but it just did not feel right (we got ugly abbreviations).
We would like to create such document for our in-house usage, but we were stuck before we've even begun.
Are you referring to the ids in the xml layouts?
I name mine based on the layout name, type of view and functionality. For example if I have a signup.xml
layout, I would name the elements inside:
[layout]_[view]_[object's purpose]
signup_text_user
signup_edit_user
signup_text_pass
signup_edit_pass
signup_btn_login
etc
The names are kind of long, but it's easy to look for the ids in code, since all my signup elements have a "signup_" prefix, and all my textviews inside the layout have "text_" and so on.
try this:
http://source.android.com/source/code-style.html#follow-field-naming-conventions
精彩评论