Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for ID naming conventions in Android? [closed]

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).

like image 706
DoubleBass Avatar asked Mar 10 '16 17:03

DoubleBass


People also ask

What is the naming convention for Android?

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.

What naming convention should be used for method names?

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.

Are naming conventions important?

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.

What is a naming convention and when is it used?

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.


2 Answers

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.

like image 83
UMESH0492 Avatar answered Oct 03 '22 05:10

UMESH0492


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.

like image 38
Ashish Kudale Avatar answered Oct 03 '22 05:10

Ashish Kudale