Question: I'm studying Android by looking at open source projects code, and what I noticed was that, in many cases, they give ids to almost all the views, even if they don't actually use those ids in code.  

For example, they give ids to `LinearLayout`, `RelativeLayout` and so on, but they don't really use those ids in code. 

Is there any reason why they do that?  

Because I think giving ids to all the views only makes me confused about what id was what view.  

Is it just a bad practice? 

Thank you in advance!

Answer: 
> 
> Is there any reason why they do that?
> 
> 
> 

No.

Technically there is no reason to do that if you are not going to use the `id` anywhere (either in `Java` or in the `XML` file).

For eg it could be a personal choice, just like naming variables or naming class depending on its purpose (here note that this could be a personal choice).

From the developer API guides:

> 
> Defining IDs for view objects is important when creating a
>  RelativeLayout. In a relative layout, sibling views can define their
>  layout relative to another sibling view, which is referenced by the
>  unique ID.
> 
> 
> 

Again,

> 
> Because I think giving ids to all the views only makes me confused
>  about what id was what view.
> 
> 
> 

You can easily sort out the confusion thing if you give proper name to the id's.
Like:

`btn_create` for **Buttons**

`tv_mobile_number` for **TextViews**

`ll_main_activity` for **LinearLayouts**

`rl_details_fragment` for **RelativeLayouts** and so on.

> 
> Is it just a bad practice?
> 
> 
> 

Technically not. But it may save you from the pain of typing id's for each and every view and may even save some time for you as well. 

As a side note, I usually prefer giving `id's` only when needed.

Hope this will help you. Cheers!
sure it some times confused, in my case I give id only to views that I will use in codes.
thank.