Best practices for ID naming conventions in Android?
My pratice:
@+id/SummaryActivityName_SummaryViewType_Description
For example:
@+id/MyAct_Txv_UserName
@+id/MyAct_Grd_GridUsers
@+id/MyFrag_LstView_UserList
This way is much better to seek Views on a big project. I hope it help.
Edit: Put the same ID name on a variable name. Example:
private TextView MyAct_Txv_UserName;
protected void onCreate(...){
MyAct_Txv_UserName = (TextView) findViewById(R.id.MyAct_Txv_UserName);
...
}
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.