In the previous article, we briefly introduced the use of roboguice ([7] use of the injection framework roboguice :( your first custom binding). Today, let's take a look at the fragment annotation.
(1): Like activity, we can also use annotations in fragment. You need to take the following steps.
①: Compile an inheritance and robofragment fragment;
②: Set your layout (if view injection is used)
③: Inject your view space, resource files (resources), objects, etc.
(2) Example:
public class MyFragment extends RoboFragment { // Inject your view @InjectView(R.id.text1) TextView nameTextView; // Inflate your view as you normally would for any fragment... @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.my_layout, container, false); } }(3) Compatibility
Currently, roboguice 3.0 supports native and fragment compatibility. The package names are as follows:
- Package
Roboguice. Fragment(For support fragments)
- Package
Roboguice. Fragment. Provided(For native Android SDK 11 + fragments)
[8] use of the injection framework roboguice: (your first injected fragment)