For e.g., is the following code is right?
private LinearLayout layout1;
private LinearLayout layout2;
private LinearLayout layout3;
For e.g., is the following code is right?
private LinearLayout layout1;
private LinearLayout layout2;
private LinearLayout layout3;
No, there is no harm in it. However, if you are using some kind of view injection library like ButterKnife
, it won't let you define your views as private
. The reason is the following:
The reason that Butter Knife requires views not be private is that it actually generates code which sets the fields. The code that it generates lives in the same package as your class which is why the field must be package-private, protected, or public. If the field was private the generated code would fail to compile since it cannot access the private field.
Source: Butterknife View injection