FragmentArg

Kay-Uwe Janssen edited this page Nov 20, 2016 · 8 revisions

Since AndroidAnnotations 2.7

@FragmentArg

The @FragmentArg annotation indicates that a fragment field should be injected with the corresponding Fragment Argument.

The setter method in the generated builder will always have the same name as the argument. By default, the key used to bind the value is the field name, but you can change it by providing a value to the @FragmentArg annotation.

Usage example:

@EFragment
public class MyFragment extends Fragment {

  @FragmentArg("myStringArgument")
  String myMessage;

  @FragmentArg
  String anotherStringArgument;
	
  @FragmentArg("myDateExtra")
  Date myDateArgumentWithDefaultValue = new Date();

}

Method based injection

Since AndroidAnnotations 4.0.0

@EFragment
public class MyFragment extends Fragment {

  @FragmentArg("myStringArgument")
  void setOneFragmentArg(String myMessage){
    // do something with myMessage
  }
  
   void setMultipleFragmentArgs(@FragmentArg String anotherStringArgument, @FragmentArg("myDateExtra") Date myDateArgument){
    // do something with anotherStringArgument and myDateArgument
  }

}

The fragment builder will hold dedicated methods for these arguments:

MyFragment myFragment = MyFragment_.builder()
  .myMessage("Hello")
  .anotherStringArgument("World")
  .build();

21/10/2018 The 4.5.2 release is out !

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.