Why can't Butterknife find ViewHolder inside an anonymous class?

I have a ListView with an anonymous BaseAdapter :

 final ListView myList = (ListView) getActivity().findViewById(R.id.my_list); myList.setAdapter(new BaseAdapter() { 

Inside an anonymous class, I have a view holder:

 class ViewHolder { @InjectView(R.id.textField) TextView text; public ViewHolder(View view) { ButterKnife.inject(this, view); if (text == null) { text = (TextView)view.findViewById(R.id.textField); } } } 

Setting a breakpoint confirms: Butterknife always leaves a text null field, but a direct call to findViewById works fine. If I translate the ViewHolder class from an anonymous class, making it a member of my main class, Butterknife works fine. Can someone explain why?

+6
source share

Source: https://habr.com/ru/post/973907/


All Articles