Search code examples
androidbutterknife

ButterKnife how to use @OnClick with parameters


I have a TextView and setting the text by calling setItem

public void setItem(String text){
    commentsTextView.setText(text);
}

With butterknife should be like this:

private String mText;

public void setItem(String text){
    mText = text;
}

@OnClick(R.id.commentsTextView)
protected void comment(){
    commentsTextView.setText(mText);
}

but this does not look right. What is the right way to use @OnClick, with parameters not just make a Toast like all the examples shows?


Solution

  • Butter Knife's callbacks are methods on a class so if you want additional parameters those would need to be fields on that class.

    Look into this.