1
Let’s assume that I have an Activity with its layout and, using the Butterknife and the Viewholder Pattern, I create a nested class in which I pass the View root and inject the Butterknife in it. The goal would be for example, instead of passing View by View to an auxiliary class, I would pass the user class of Viewholder Pattern. Follow an example:
public class LoginActivity extends AppCompatActivity {
private ViewHolder viewHolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
viewHolder = new ViewHolder(findViewById(R.id.layout_raiz));
// faz algumas tarefas que poderiam deixar o código
// da Activity sujo
new VerificarLogin(viewHolder);
}
static class ViewHolder {
@BindView(R.id.et1)
EditText email;
@BindView(R.id.et2)
EditText senha;
ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
The point is:
1) Would creating such a standard for Activity be bad practice? This standard should only be used when "recycling" of Views is required?
2) Is passing a Viewholder as a parameter a bad practice? (assuming that in the auxiliary class I use all views within Viewholder)
3) Using this type of practice in Activity, and passing as parameter (as in the example above), I should configure the object viewHolder = null when the Activity was destroyed?
In Verify login you use the views or their content?
– ramaral
I use both @ramaral
– Guilherme Ramos