错误:无法从静态上下文引用非静态方法unbind()

时间:2018-09-01 15:02:01

标签: android butterknife

我正在将Bind更改为BindView类,如何以不知道的正确方式编写代码,我是编码新手 请帮助我

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import static butterknife.Unbinder.*;


public View onCreateView(LayoutInflater inflater,
 @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    // TODO Auto-generated method stub code part

    View view = inflater.inflate(R.layout.fragment_device_info, container, false);
    Unbinder unbinder = ButterKnife.bind(this, view);
    mContext = getActivity();

    return view;
}


@Override
public void onDestroyView() {
    super.onDestroyView();
    Unbinder.unbind();
}

请帮助我

1 个答案:

答案 0 :(得分:0)

Unbinder unbinder; //declare it here 
 public View onCreateView(LayoutInflater inflater,
 @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    ...........
    unbinder = ButterKnife.bind(this, view); //bind it here

    .......

    return view;
}


@Override
public void onDestroyView() {
    super.onDestroyView();
    unbinder.unbind(); // then unbind it here on the same Unbinder object
}