0

I'm working to improve an android recycler view by following this simple tutorial. I found a java issue: if I declare an interface inside a non-static view holder inner class like below...

public class DumbViewHolder extends RecyclerView.ViewHolder {
    //...
    ExcellentAdventureListener listener;

    public interface ExcellentAdventureListener {
        void onMapClicked(ExcellentAdventure item);
        void onTitleClicked(ExcellentAdventure item);
    }   
    //...
}

java gives me the following error:

INNER CLASS CANNOT HAVE STATIC DECLARATION.

why? and how can I fix it?

Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Giulio Pettenuzzo
  • 786
  • 1
  • 5
  • 20
  • In your code, I can not see any `STATIC DECLARATION`. – CoXier Dec 24 '17 at 02:28
  • see this https://stackoverflow.com/questions/31956340/recyclerview-inner-classes-cannot-have-static-declaration – Gaurav Dec 24 '17 at 02:33
  • 'Non-static inner' is a tautology. Define the interface one level out, or indeed define the *class* at the outer level, which is what must be happening in the your citation. You can't put interfaces into inner classes. – user207421 Dec 24 '17 at 03:55

1 Answers1

1

Why are you putting your interface in an inner class? It will work fine outside.

Simply take your interface and keep it as a variable in your adapter and check if the object passed to your adapter implements the interface methods, then cast that object to your interface.