In the last article, we briefly introduced the use of RoboGuice ( [7] RoboGuice injected into the framework: (Your First Custom Binding) ) , today we will look at the annotations of fragments
(1): Brief introduction: Like Activity, we can also use annotations in Fragment, you need the following steps.
①: Write a Fragment that inherits from RoboFragment;
②: Set up your layout (assuming 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): Compatible
Now RoboGuice 3.0 version number has supported native and compatible Fragment, they are located in the package name such as the following:
- package
roboguice.fragment
(for support fragments) - package
roboguice.fragment.provided
(for native android SDK 11+ fragments)