[3] use of the Injection framework RoboGuice: (Your First Resource Injection) and roboguiceinjection

Source: Internet
Author: User

[3] use of the Injection framework RoboGuice: (Your First Resource Injection) and roboguiceinjection

In the previous article, we briefly introduced the use of RoboGuice ([2] use of the Injection framework RoboGuice :( Your First View Injection). Today, let's take a look at the method of using annotations for resource files:

To use annotations for Chinese source files in an Activity, you must perform the following two steps:

①: Create an Activity that inherits the RoboActivity

②: Use @ InjectResource to annotate resource files

Below we will implement the following. Now we have an Animation file my_animation.xml under the res/anim directory. Then we use @ InjectResource to get the Animation object.

public class MyActivity extends RoboActivity {    @InjectResource(R.anim.my_animation) Animation myAnimation;    // the rest of your code}
This is simple. Now you can directly use the myAnimation object. In addition to animation, we also use annotations to use any types of resource files, such as strings, drawables, and animations.

@ ContentView (R. layout. activity_main) public class MainActivity extends RoboActivity {@ InjectView (R. id. TV _one) TextView mTextView_one; @ InjectView (R. id. img_one) ImageView mImage_one; @ InjectResource (R. string. app_name) String mString; @ InjectResource (R. anim. animation_rotale_layout) Animation mAnimation; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // sets the text mTextView_one.setText (mString); // sets the image animation mImage_one.startAnimation (mAnimation );}
Instance code and libs directory support package download: http://download.csdn.net/detail/jiangqq781931404/8079951




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.