Android Roboguice Use Guide (2) First example Hello World

Source: Internet
Author: User
Tags filter

First of all, if you add Guice and Roboguice libraries to your project.

Download Roboguice and Guice-2.0-no_aop.jar (not guice-3.0), or download

Create a new Android project, such as Guicedemo, the target platform Android1.5 above.

In general, you can add a Lib directory under the project, copy two jar files to the Lib directory, and then pass: Project > Properties > Java build Path > Libraries > Add External J ARs

After adding references to the Guice and roboguice libraries, you can start writing the first example that uses Roboguice.

Steps to use Roboguice:

1. Create a roboapplication subclass Guiceapplication,guiceapplication as a subclass of appliacation, so you need to modify the Androidmanifest.xml, Point the name of the application to this class. See Android Simple development tutorial nine: Creating an application framework

<application android:name= "Guiceapplication"

android:icon= "@drawable/icon" android:label= "@string/app_name" >

<activity android:name= ". Guicedemo "

Android:label= "@string/app_name" >

<intent-filter>

< action android:name= "Android.intent.action.MAIN"/>

<category android:name= "Android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>

</application>

2. In this simple example, it uses the layout definition 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= "Fill_parent"

android:layout_height= "Fill_parent"

>

<textview

Android:id= "@+id/hello"

Android:layout_width= "Fill_parent"

android:layout_height= "Wrap_content"

android:text= "@string/hello"

/>

</linearlayout>

We have defined a textview, and its ID is hello.

Assuming that this application uses a igreetingservice, it has a method getgreeting () returns a string, as for Igreetingservice How to implement, Guidedemo does not need to care.

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.