Android Roboguice Usage Guide (inject)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.