Android Butterknife-片段中的绑定

Android Butterknife-片段中的绑定

问题描述:

我第一次使用Butterknife,但一定有问题.我有一个片段以及一个Listview和一个TextView仅用于测试,但是Butterknife不会绑定我的变量:

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:

public class MyFragment extends Fragment {

    @Bind(R.id.resultListView) ListView resultList;

    @Bind(R.id.textView1) TextView test;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        ButterKnife.bind(this, view);
        System.out.println(resultList); //null
        System.out.println(view.findViewById(R.id.resultListView)); //works
        System.out.println(test); //null
        System.out.println(view.findViewById(R.id.textView1)); //works
        return view;
    }

}

无例外.手动绑定有效,因此我的视图必须在其中.

No exception or anything. Manual binding works so my Views must be there.

从代码角度来看,这看起来还不错.因此,基于注释,您似乎需要在Eclipse中设置注释处理: http://jakewharton.github.io/butterknife/ide-eclipse.html

Code-wise, that looks just fine. So based on the comments, it looks like you need to setup the annotation processing in Eclipse: http://jakewharton.github.io/butterknife/ide-eclipse.html