studio jakewharton butter android butterknife

android - studio - implementation com jakewharton butterknife 7.0 1



Butterknife Android-encuadernaciĆ³n en fragmento (3)

Estoy usando Butterknife por primera vez, pero algo debe estar mal. Tengo un fragmento, una vista de lista y una vista de texto para probar, pero Butterknife no vincula mis variables:

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; } }

Sin excepción ni nada. El enlace manual funciona, por lo que mis Vistas deben estar allí.



Este trabajo para mí:

Gradle

compile ''com.jakewharton:butterknife:8.6.0'' annotationProcessor ''com.jakewharton:butterknife-compiler:8.6.0''

Código

. ... @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"); ... .


tampoco te olvides de soltar cuando hayas terminado:

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(); }