Roboguice also provides injection support for accessing various resources in the Res directory drawable, Arrary, String, and so on. It is easy to apply the resources through @injectresource.
This example modifies the Android Apidemos sample resolution: Content->resources->resources uses the inject resource method to access resources.
public class
Injectresourcedemo extends Roboactivity {
@InjectView (r.id.styled_text) TextView styled_text;
@InjectView (R.id.plain_text) TextView plain_text;
@InjectView (r.id.res1) TextView res1;
@Inject Resources Res;
@InjectResource (r.string.styled_text) string str;
@Override public
void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.injectresource);
Use res to get the string
charsequence cs=res.gettext (r.string.styled_text);
The use of
//Charsequence instead of a String
//So we don ' t lose the style info.
Styled_text.settext (CS);
Use the same resource, but convert it
to//a string, which causes it
//To lose the style information.
Plain_text.settext (str);
Res1.settext (CS);
}
This example downloads: Http://www.imobilebbs.com/download/android/roboguice/InjectResourceDemo. zip
View a full set of articles: Http://www.bianceng.cn/OS/extra/201301/34950.htm