ButterKnife binding from parent view

52 views Asked by At

so I'm fairly new to ButterKnife and I'm trying to achieve the following:

I have a partial_ view that I'm including multiple times in my layout, and I want to bind each of the partial_ views to different variables.

Partial:

<ViewGroup...
  <TextView android:id="@+id/tv_1"/>
  <TextView android:id="@+id/tv_2"/>
</ViewGroup>

Activity layout:

<ViewGroup...
  <include id="@+id/partial_A" layout="layout/partial"/>
  <include id="@+id/partial_B" layout="layout/partial"/>
</ViewGroup>

Activity:

ViewGroup partial_A = findViewById(R.id.partial_A);
ViewGroup partial_B = findViewById(R.id.partial_B);
TextView tv_A_1 = (TextView) partial_A.findViewById(R.id.tv_1);
TextView tv_A_2 = (TextView) partial_A.findViewById(R.id.tv_2);
TextView tv_B_1 = (TextView) partial_B.findViewById(R.id.tv_1);
TextView tv_B_2 = (TextView) partial_B.findViewById(R.id.tv_2);

Can this be simplified with ButterKnife?

Thanks.

0

There are 0 answers