Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID naming conventions #75

Open
steelrooter opened this issue Aug 13, 2015 · 2 comments
Open

ID naming conventions #75

steelrooter opened this issue Aug 13, 2015 · 2 comments

Comments

@steelrooter
Copy link

Please include some best practices about naming conventions for android:id of components in XML layouts.

@dkhmelenko
Copy link

I would suggest the following:

  • id should contain the prefix of the layout in which it exists. For example, inside the layout activity_auth.xml all ids of controls will start with activity_auth;
  • id should contain clear description of the control and what it does. Like connect_options, user_name etc.;
  • each id should have a suffix which defines the type of the control. For example, btn for the Button (like activity_auth_connect_btn).

Like in any framework some controls become deprecated, another controls are introduced. That's why there is a sense to define the following basic suffixes for the controls:

  • btn - button control (Button, RadioButton, ImageButton, CheckBox, custom button)
  • txt - TextView control
  • input - EditText or any input related control
  • list - for list control (ListView, GridView, RecyclerView)
  • selector / spinner - for Spinner control

I use such naming rules for a while and think they are quite convenient. They give an opportunity not to intersect ids between different layout. Also it's much easier to find related control by id inside the layout.

@peter-tackage What do you think?

@peter-tackage
Copy link
Contributor

I'm only slightly late on this one. I've made another ticket to revise this #154 once I've gather more feedback internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants