-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance Fragments
Since AndroidAnnotations 2.1
Prior to AndroidAnnotations 2.6, there was no support for fragment injection. However, we made sure that at least extending FragmentActivity instead of Activity didn't break AndroidAnnotations:
@EActivity(R.id.main)
public class DetailsActivity extends FragmentActivity {
}Since AndroidAnnotations 2.6
AndroidAnnotations supports both android.app.Fragment and android.support.v4.app.Fragment, and automatically uses the right APIs based on the fragment types.
To start using AndroidAnnotations features in a fragment, annotate it with @EFragment:
@EFragment
public class MyFragment extends Fragment {
}AndroidAnnotations will generate a fragment subclass with a trailing underscore, e.g. MyFragment_. You should use the generated subclass in your xml layouts and when creating new instance fragments:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/myFragment"
android:name="com.company.MyFragment_"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>Programmatically:
MyFragment fragment = new MyFragment_();You can now use all kind of annotations in your fragment:
@EFragment
public class MyFragment extends Fragment {
@Bean
SomeBean someBean;
@ViewById
TextView myTextView;
@App
MyApplication customApplication;
@SystemService
ActivityManager activityManager;
@Click
void myButton() {
}
@UiThread
void uiThread() {
}
@AfterInject
void calledAfterInjection() {
}
@AfterViews
void calledAfterViewInjection() {
}
}View injection and event listener binding will only be based on views contained inside the fragment. Note, however, that it's isn't currently the case for
@EBeaninjected inside fragments: they have access to the activity views.
14/06/2012 The 2.6 release is out
- Get started!
- Cookbook, full of recipes
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow