Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" warning for methods that use the 'OnClick' Annotation of ButterKnife.I noticed that Eclipse doesnt give this warning for the 'OnClick' methods. Thanks in advance

like image 421
TMS Avatar asked Apr 30 '14 07:04

TMS


2 Answers

The correct way in Android Studio to suppress these warnings is to press Alt+Enter on the method giving the Method 'yourFunction()' is never used warning, and selecting

Suppress for methods annotated by 'butterknife.OnClick' 
like image 78
Osvald Ivarsson Avatar answered Sep 20 '22 11:09

Osvald Ivarsson


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 
like image 30
Konrad Morawski Avatar answered Sep 23 '22 11:09

Konrad Morawski