本文介绍了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
这篇关于Android Butterknife-片段中的绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!