Revolutionair Revolutionair - 3 months ago 31
Android Question

Views don't get injected by AndroidAnnotations in DialogFragment

The @ViewById annotations are not working in my DialogFragment.

I use

@EFragment(R.layout.mydialogfragment)


I create the fragment by doing

MyDialogFragment_.builder()
.build()
.init(someObject, new ClickListener() {...})
.show(getFragmentManager(), "myDialog");


where
init()
is my custom method which returns the
MyDialogFragment
for chaining.

I didn't override
OnCreateDialog
, nor did I override
onCreateView
, and I'm not using any of the
@After...
annotations of AndroidAnnotations.

I'm trying to use the injected views in my
init()
method, but they are null.

Answer

Just as I finished typing the question I realized what was wrong. I was assuming views would be injected by the time build() returned so I could use them in the init() method, but they weren't. The fix was to annotate another method with the @AfterViews annotation and do the view related initialization there.