LeonardoSibela LeonardoSibela - 3 months ago 21
Android Question

Binding view with butterknife on android.R.layout.simple_list_item_1

I created an class that extends RecyclerView.Adapter.

I'm using as layout the android.R.layout.simple_list_item_1.

On my ViewHolder, I was trying to map it's TextView text1 on a TextView variable, using this:

myTextView = (TextView) itemView.findViewById(android.R.id.text1);


This works like a charm, but I'm also using butterknife, and as far as I searched, I cant pass android.R.id.text1 anywhere.

What I tryed so far:

@BindView(android.R.id.text1)
TextView myTextView;


and also, on the constructor of my ViewHolder:

private ViewHolder(View itemView) {
super(itemView);
myTextView = ButterKnife.findById(itemView, android.R.id.text1);
}


Is there a way to make it work with ButterKnife?

Answer

You just have to pass the holder view which contains that text with id like this:

@BindView(android.R.id.text1)
TextView myTextView;
private ViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
}
Comments