I saw this link first but it didn't seem to have much activity: Naming convention for IDs in Android
I am curious what the best practice is for naming IDs for the various items in Design View on Android Studio.
Right now I'm doing stuff like this: If it's an TextView with the text "Welcome To My Program", I'll name it welcomeTextViewID
. If it's a Button that starts some subroutine called doStuff
, I might call it doStuffButtonID
.
In other words I use a sort of descriptor + datatype + ID
convention.
Is this considered bad practice? I always heard mixed things on using descriptors inside the name. For example in a language like C++ naming a string variable nameString
(since if you change the data type later you have to also update the name).
It's the end of an era at Google: The company's Android mobile platform is dropping its long-running dessert-themed naming convention, switching instead to a simple numerical format. Beginning with the release of Android 1.5, the mobile popular platform Google acquired along with its creator Android Inc.
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.
Naming conventions make sure users know how to name digital assets so that filenames or titles are consistent and contain all the right information. They help you store and organise your files. Without them, your asset library can become chaotic and make it much harder to find images when you need them.
A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.
Checkout --> https://github.com/umesh0492/android-guidelines
Further ID naming
IDs should be prefixed with the name of the element in lowercase underscore. For example:
+---------------------+ | Element | Prefix | |-----------+---------+ | TextView | text_ | | ImageView | image_ | | Button | button_ | | Menu | menu_ | +-----------+---------+
view example:
<ImageView android:id="@+id/image_profile" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Menu example:
<menu> <item android:id="@+id/menu_done" android:title="Done" />
The best guidelines I have ever seen and I do follow them.
I follow this type of Naming convention for IDs in Android.
Ex:
Button : btSubmit TextView : tvWelcome EditText : etEmailId CheckBox : cbHobbies RadioButton : rbMale LinearLayout : llPanel
By just looking at id you can identify your component. and use the same id in java to avoid confusion.
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