I'm currently trying to use the ButterKnife library for Android to handle some template code ( https://github.com/JakeWharton/butterknife )
I have a setting, and I got it half working, but I ran into a problem that I cannot fix: /
I have a fragment that contains one single ListView element, and to this ListView I add a footer containing several elements.
This is the code snippet from my snippet using the library:
public class UsersFragment extends Fragment {
@InjectView(R.id.users_listview_id) AutoUpdatingListView list;
private View footerView;
@InjectView(R.id.add_user_footer_firstname_edittext_id) BootstrapEditText firstnameEditText;
@InjectView(R.id.add_user_footer_middlename_edittext_id) BootstrapEditText middlenameEditText;
@InjectView(R.id.add_user_footer_lastname_edittext_id) BootstrapEditText lastnameEditText;
@InjectView(R.id.add_user_footer_cancel_button_id) BootstrapButton cancelButton;
@InjectView(R.id.add_user_footer_okay_button_id) BootstrapButton okayButton;
@InjectView(R.id.add_user_footer_facebook_button) BootstrapCircleThumbnail facebookButton;
@InjectView(R.id.add_user_footer_google_plus_button) BootstrapCircleThumbnail googlePlusButton;
@InjectView(R.id.add_user_footer_twitter_button) BootstrapCircleThumbnail twitterButton;
@InjectView(R.id.add_user_footer_linkedin_button) BootstrapCircleThumbnail linkedInButton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.user_fragment, container, false);
footerView = ((LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.add_user_footer_view, null, false);
ButterKnife.inject(this, rootView);
list.setAdapter(adapter);
}
}
The above code does NOT work, as I can only enter 1 view, and if I try with both of them (2x injections), the second input overrides the first, leaving me with zero values.
, , i, findViewById().
, , ButterKnife ( 100%):
list = (AutoUpdatingListView) rootView.findViewById(R.id.users_listview_id);
firstnameEditText = (BootstrapEditText) footerView.findViewById(R.id.add_user_footer_firstname_edittext_id);
middlenameEditText = (BootstrapEditText) footerView.findViewById(R.id.add_user_footer_middlename_edittext_id);
lastnameEditText = (BootstrapEditText) footerView.findViewById(R.id.add_user_footer_lastname_edittext_id);
, "rootView", "footerView" findViewById.
- ? ..