Hot questions for Using Butter Knife in android fragments

Top 10 Java Open Source / Butter Knife / android fragments


Butterknife is working well when i am using it on Activities, but not working when I am trying to use it in a fragment :

public class SettingsFragment extends Fragment {
private static final String TAG = "SettingsFragment";

@BindView(      TextView _settingsMail;
@BindView(   TextView _passwordMail;
@BindView(      TextView _tokenMail;

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    //returning our layout file
    final View view = inflater.inflate(R.layout.fragment_3_settings, container, false);
    ButterKnife.bind(this, view);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getContext());
    String email = prefs.getString("email", null);
    String passwd = prefs.getString("password", null);
    String token = prefs.getString("token", null);
    return inflater.inflate(R.layout.fragment_3_settings, container, false);


You have to return the view that you already have inflated, not inflate another view again.

Instead of:

return inflater.inflate(...);

Do this:

return view;