Skip to content Skip to sidebar Skip to footer

Butterknife Is Unable To Bind Inside My Adapter Class

I have an Adapter that draws the layouts for my Navigation Drawer. My navigation drawer contains two inner xml files: One being the Header and the other being the Row. I draw these

Solution 1:

I was able to solve this problem by doing the following:

First, the api docs stated the following

Be default, views are required to be present in the layout for both field and method bindings. If a view is optional add a @Nullable annotation such as the one in the support-annotations library.

@Nullable @Bind(R.id.title) TextView subtitleView;

http://jakewharton.github.io/butterknife/javadoc/

Now since I had different elements to bind coming from different xml files, I had to tag them as @Nullable because it's possible that they won't even be bindable to begin with. I changed my code to do the following :

@Nullable@Bind(R.id.drawer_row_icon)
ImageView imageView;
@Nullable@Bind(R.id.drawer_row_text)
TextView textView;
@Nullable@Bind(R.id.drawer_row_id)
FrameLayout listRow;
@Nullable@Bind(R.id.driverName)
TextView driverNameText;

While also moving the ButterKnife.bind() outside of my IF-ELSE Block.

Solution 2:

You are binding twice. You cannot call bind twice on the same view. It is only doing your findviewbyid calls. Call bind once above your if block.

public ViewHolder(View itemView, int viewType) {
    super(itemView);

    this.viewType = viewType;

    ButterKnife.bind(this, itemView);
    if (viewType == ROW_TYPE) {
        imageView.setOnClickListener(this);
        textView.setOnClickListener(this);
        listRow.setOnClickListener(this);
    }
}

Post a Comment for "Butterknife Is Unable To Bind Inside My Adapter Class"