Android Butterknife - binding in fragment

前端 未结 3 2017
半阙折子戏
半阙折子戏 2021-02-11 12:19

I\'m using Butterknife for the first time but something must be wrong. I have a fragment and a Listview and a TextView just for testing but Butterknife wont bind my variables:

3条回答
  •  清歌不尽
    2021-02-11 13:11

    also dont forget to release when you are finish :

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

提交回复
热议问题