Search code examples
javaandroidinheritanceandroid-fragmentsnested-class

Implement static nested class' interface in outer class


I am writing an android class, and I have found that a good way to communicate between fragments and activities is by way of listeners, which define interfaces. In my code, I have defined a static fragment class inside of my main activity. I want to implement the fragment's interface in the outer class, but I can't seem to get the outer class to cleanly implement this code. I know how to write the implementation. The problem is actually declaring that the activity should implement this interface. How do I accomplish this? Code below

public class TransferMain extends FragmentActivity implements ServiceConnection,
    ActionBar.TabListener, MainTransferFragment.OnTransferActionListener {

MainTransferFragment is the nested class of TransferMain. The declaration shown currently results in an error, as OnTransferActionListener requires that the entire class identifier be named. E.g. TransferMain.MainTransferFragment.OnTransferActionListener.

However, when declared as below, java claims cyclic inheritance, which throws an error.

public class TransferMain extends FragmentActivity implements ServiceConnection,
    ActionBar.TabListener, TransferMain.MainTransferFragment.OnTransferActionListener 

What's the move Stack?


Solution

  • You need to move your fragment to a separate file.

    Refer to this answer: Cyclic inheritance when implementing inner interface in enum