Android Dependency Injection Function library Roboguice (i)

Source: Internet
Author: User

Roboguice is a dependency injection framework for Android apps, and using Google's official Guice location greatly simplifies Android's dependency injection. Using him makes programming easier and more fun.

Using Roboguice requires several jars click download Download to know import into your own project

Using Roboguice is an activity page that needs to inherit roboactivity

/** * */package com.example.roboguicetest;import com.google.inject.inject;import roboguice.activity.RoboActivity; Import Roboguice.inject.injectresource;import Roboguice.inject.injectview;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import android.widget.toast;/** * must inherit Roboactivity class Roboactivity is activity subclass */public class Mainactivity extends Roboactivity {/** * control injection (equivalent to button BtnShow1 = (button) Findviewbyid (R.ID.BTN_SHOW1);) */@InjectView (R.ID.BTN_SHOW1) button btnShow1; @InjectView (r.id.btn_show2) button btnshow2;/** * Resource injection */@InjectResource (r.string.toast) string toast /** * System Service Injection */@InjectLayoutInflater inflater; @InjectView view;/** * Pojo Object injection */@InjectUserInfo info;@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.main); Btnshow1.settext ("Hello!" "); Btnshow2.settext (" OK "); Toast.maketext (This, toast, TOAST.LEngth_long). Show (); view = Inflater.inflate (R.layout.main, null); Info.setname ("XIONGLH"); Info.setpwd ("123"); Btnshow1.setonclicklistener (onclick);} Private Onclicklistener onclick = new Onclicklistener () {@Overridepublic void onclick (View v) {Toast.maketext ( Mainactivity.this,info.getname () + "--" + info.getpwd (), Toast.length_long). Show ();}};}

Simple instance Download

Android Dependency Injection Function library Roboguice (i)

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.