I've got a ListView
with an anonymous BaseAdapter
:
final ListView myList = (ListView) getActivity().findViewById(R.id.my_list);
myList.setAdapter(new BaseAdapter() {
Inside that 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 the text
field null
, but directly calling findViewById
works fine. If I move the ViewHolder
class out of the anonymous class, making it a member of my main class, Butterknife works fine. Can someone explain why?
static class ViewHolder
– Cake