8

i am having trouble with android-annotations and inheritance:

@EFragment(R.layout.fragment_foo)
public class TestBaseFragment {
    @AfterViews
    public void afterTestBaseFragmentViews() {
   }
}

@EFragment(R.layout.fragment_foo)
public class TestFragment extends TestBaseFragment {
    @AfterViews
    public void afterTestFragmentViews() {
   }
}

generates:

public final class TestFragment_
    extends TestFragment
{
    ...

    private void afterSetContentView_() {
        afterTestFragmentViews();
        afterTestBaseFragmentViews();
    }
    ...

how can I make sure that afterTestBaseFragmentViews() is called before afterTestFragmentViews() ? Or can you point me to any document which describes how to do inheritance with AndroidAnnotations?

marcellsimon
  • 666
  • 7
  • 14
ligi
  • 39,001
  • 44
  • 144
  • 244

1 Answers1

11

It's just some sort of workaround

Using an abstract class:

@EFragment(R.layout.fragment_foo)
public abstract class TestBaseFragment {

    @AfterViews
    protected void afterTestBaseFragmentViews() {
        // do something
        afterView();
    }

    protected abstract void afterView();

}

@EFragment(R.layout.fragment_foo)
public class TestFragment extends TestBaseFragment {

    @Override
    protected void afterView() {
        // do something after BaseFragment did something
    }

}

Using simple subclassing:

@EFragment(R.layout.fragment_foo)
public class TestBaseFragment {

    @AfterViews
    protected void afterTestBaseFragmentViews() {
        afterView();
    }

    public void afterView() {
        // do something
    }

}

@EFragment(R.layout.fragment_foo)
public class TestFragment extends TestBaseFragment {

    @Override
    public void afterView() { 
        super.afterView();
        // do something after BaseFragment did something
    }

}

I hope this is what you were looking for. (Not tested - just written in notepad)

Basic Coder
  • 10,882
  • 6
  • 42
  • 75
  • 4
    method ```afterTestBaseFragmentViews``` should not be private. In this case AA can't access this method – ruX Jun 05 '13 at 17:39
  • what if TestBaseFragment has annotations like ViewById ? In my case, these annotations are not seen in the generated class TestFragment_. The same for annotation Click. – Serge Tahé Mar 08 '16 at 10:41