In the example Android Roboguice use Guide (2): The first example Hello World describes the basic steps for using Roboguice development:
Create a roboapplication subclass Guiceapplication,guiceapplication as a appliacation subclass, modify Androidmanifest.xml to Application Name points to this class.
Change the class base class originally derived from the activity to roboactivity (or other related activity).
Overload the Configuatation method definition bindings in Abstractandroidmodule if necessary.
If you do not use Roboguice, if you need to access a view defined in layout in an activity, you generally need to use Findviewbyid to find the corresponding view and cast it to the corresponding class, if you need to access a lot of view, Duplication of code is cumbersome.
If you use Roboguice's inject view, the code is simple and easy to read, and the basic usage of @Inject view is as follows:
@InjectView (r.id.xxx) ViewType viewinstance;
R.id.xxx the ID that is defined in layout for the desired view, such as R.id.textview1
ViewType is the type of view you want, such as TextView
Viewinstance is the variable name.
We define a injectview.xml, as follows:
<?xml version= "1.0″encoding=" utf-8″?>
< LinearLayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<textview
Android:id= "@+id/textview1″
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/injectview"
/>
<textview
Android:id= "@+id/textview2″
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/injectview"
/>
<textview
Android:id= "@+id/textview3″
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/injectview"
/>
<textview
Android:id= "@+id/textview4″
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/injectview"
/>
<button android:id= "@+id/button"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Center_vertical"
android:text= "@string/clickmebutton"/>
</LinearLayout>