Remove “Method is never used” warning for OnClick annotation in Android Studio

后端 未结 4 1928
Happy的楠姐
Happy的楠姐 2020-12-30 18:35

Sorry if this question has been asked before. I am using the Butterknife 5.0 with the latest version of Android Studio(0.5.7). How can I remove the \"Method is never used\"

4条回答
  •  [愿得一人]
    2020-12-30 19:30

    Simply add this annotation:

    @SuppressWarnings("unused")
    

    Just like that:

    @SuppressWarnings("unused")
    @OnClick(R.id.myButton)
    public void clickHandler()
    {
        // ...
    }
    

    My personal preference (which I see as good practice) is to add a comment with a brief explanation:

    @SuppressWarnings("unused") // it's actually used, just injected by Butter Knife
    

提交回复
热议问题