ButterKnife:绑定我们的Activity和Fragme

2017-07-04  本文已影响0人  zhong_bao

1、Activity的绑定:
ButterKnife.bind(this);

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activtiy_battery);
        ButterKnife.bind(this);
}

2、Fragment的绑定:

 @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
 @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.f_modify,null);
        ButterKnife.bind(this,view);
        initReceiver(new String[]{action_getData,action_update});
        return view;
    }

注意这里的this,不能改用getActivity()方法,否则会报错。

上一篇下一篇

猜你喜欢

热点阅读