@Retention(value=CLASS) @Target(value={FIELD,METHOD,PARAMETER}) public @interface FragmentById
Use it on android.app.Fragment or android.support.v4.app.Fragment fields or methods with applicable parameters in activity classes to retrieve and inject a fragment.
The annotation value should be one of R.id.* fields. If not set, the field or method name will be used as the R.id.* field name.
Note: This can only inject an existing fragment, not create them.
Example :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/myFragment"
android:name="mypackage.MyFragment_"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
@EActivity(R.layout.main)
public class MyActivity extends Activity {
// all injected fragment will be the same
@FragmentById
public MyFragment myFragment;
@FragmentById(R.id.myFragment)
public MyFragment myFragment2;
@FragmentById
void singleInjection(MyFragment myFragment) {
// do stuff
}
void multiInjection(@FragmentById MyFragment myFragment, @FragmentById(R.id.myFragment) MyFragment myFragment2) {
// do stuff
}
}
To use the getChildFragmentManager() to inject the
Fragment, set the childFragment() annotation parameter
to true. You can only do this if the annotated field is in a
class which extends android.app.Fragment or
android.support.v4.app.Fragment and the
getChildFragmentManager() method is available.
Example :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/myChildFragment"
android:name="mypackage.MyChildFragment_"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
@EFragment(R.layout.parentfragment)
public class MyParentFragment extends Fragment {
@FragmentById(childFragment = true)
MyChildFragment myFragment;
}
EFragment,
FragmentArg,
FragmentByTag| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
childFragment
Whether to use
getChildFragmentManager() or
getFragmentManager() to obtain the Fragment. |
String |
resName
The resource name which refers to the id of the Fragment.
|
int |
value
The R.id.* field which is the id of the Fragment.
|
public abstract int value
public abstract String resName
Copyright © 2010–2018 simpligility technologies inc.. All rights reserved.