[Android/예제] Hello World

android/구글관련/예제 2009. 1. 7. 21:01
간단한 설명
어디서나 볼 수 있는 Hello World.

안드로이드 어플리케이션은 다음과 같은 덩어리로 이루어진다.
1. 진짜 소스 ( 개발자가 직접 작성해야 하는것 )
2. 레이아웃 관련 XML
3. 각종 리소스 ( 이미지, 각종 단어들... )
4. 어플리케이션 관련 설정

이중에서 2,3,4는 이클립스 플러그인에서 쉽게 작성할 수 있도록 도와 준다.

자세한것들은 다음에 다루도록 하자.


소스코드
src/com.ggaman.android.sample.Test.java
  1. package com.ggaman.android.sample;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5.   
  6. public class Test extends Activity {  
  7.     /** Called when the activity is first created. */  
  8.     @Override  
  9.     public void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         setContentView(R.layout.main);  
  12.     }  
  13. }  


src/com.ggaman.andorid.sample.R.java
  1. /* AUTO-GENERATED FILE.  DO NOT MODIFY. 
  2.  * 
  3.  * This class was automatically generated by the 
  4.  * aapt tool from the resource data it found.  It 
  5.  * should not be modified by hand. 
  6.  */  
  7.   
  8. package com.ggaman.android.sample;  
  9.   
  10. public final class R {  
  11.     public static final class attr {  
  12.     }  
  13.     public static final class drawable {  
  14.         public static final int icon=0x7f020000;  
  15.     }  
  16.     public static final class layout {  
  17.         public static final int main=0x7f030000;  
  18.     }  
  19.     public static final class string {  
  20.         public static final int app_name=0x7f040001;  
  21.         public static final int hello=0x7f040000;  
  22.     }  
  23. }  


res/layout/main.xml
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <TextView    
  8.     android:layout_width="fill_parent"   
  9.     android:layout_height="wrap_content"   
  10.     android:text="@string/hello"  
  11.     />  
  12. </LinearLayout>  


res/values/strings.xml
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="hello">Hello World, Test</string>  
  4.     <string name="app_name">AppName</string>  
  5. </resources>  


res/drawable/icon.png


AndroidManifest.xml
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.       package="com.ggaman.android.sample"  
  4.       android:versionCode="1"  
  5.       android:versionName="1.0.0">  
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  7.         <activity android:name=".Test"  
  8.                   android:label="@string/app_name">  
  9.             <intent-filter>  
  10.                 <action android:name="android.intent.action.MAIN" />  
  11.                 <category android:name="android.intent.category.LAUNCHER" />  
  12.             </intent-filter>  
  13.         </activity>  
  14.     </application>  
  15. </manifest>   


: