Ответ 1
По коду, это выглядит просто отлично. Поэтому, основываясь на комментариях, похоже, вам нужно настроить обработку аннотаций в Eclipse: http://jakewharton.github.io/butterknife/ide-eclipse.html
Я использую Butterknife в первый раз, но что-то должно быть неправильно. У меня есть фрагмент, Listview и TextView только для тестирования, но Butterknife не свяжет мои переменные:
public class MyFragment extends Fragment {
@Bind(R.id.resultListView) ListView resultList;
@Bind(R.id.textView1) TextView test;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_my, container, false);
ButterKnife.bind(this, view);
System.out.println(resultList); //null
System.out.println(view.findViewById(R.id.resultListView)); //works
System.out.println(test); //null
System.out.println(view.findViewById(R.id.textView1)); //works
return view;
}
}
Никакого исключения или чего-либо еще. Ручная привязка работает, поэтому мои представления должны быть там.
По коду, это выглядит просто отлично. Поэтому, основываясь на комментариях, похоже, вам нужно настроить обработку аннотаций в Eclipse: http://jakewharton.github.io/butterknife/ide-eclipse.html
Эта работа для меня:
Gradle
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
код
.
...
@BindView(R.id.text_input)
TextView text_input;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
ButterKnife.bind(this, view);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
text_input.setText("Lorem Ipsum");
...
.
также не забудьте освободить, когда вы закончите:
private Unbinder unbinder;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.finalisation_step_fragment, container, false);
unbinder = ButterKnife.bind(this, v);
//initialize your UI
return v;
}
...
@Override public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}