当前位置: 代码迷 >> Android >> Android学习札记(5)——Android——HelloWorldDemo
  详细解决方案

Android学习札记(5)——Android——HelloWorldDemo

热度:125   发布时间:2016-05-01 15:51:41.0
Android学习笔记(5)——Android——HelloWorldDemo

工程目录结构:


??? HelloWorldActivity.java程序清单

Helloworldactivity.java代码
  1. package?com.oristand;??
  2. ??
  3. import?android.app.Activity;??
  4. import?android.os.Bundle;??
  5. ??
  6. public?class?HelloWorldActivity?extends?Activity?{??
  7. ????/**?Called?when?the?activity?is?first?created.?*/??
  8. [email protected]
  9. ????public?void?onCreate(Bundle?savedInstanceState)?{??
  10. ????????super.onCreate(savedInstanceState);??
  11. ????????setContentView(R.layout.main);//到layout目录下会对应一个main.xml配置文件,改文件决定了你要使用的那些组件,以及组件的属性,比如TextView、EditText、Button等??
  12. ????}??
  13. }??
package com.oristand;import android.app.Activity;import android.os.Bundle;public class HelloWorldActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);//到layout目录下会对应一个main.xml配置文件,改文件决定了你要使用的那些组件,以及组件的属性,比如TextView、EditText、Button等    }}

?

?? ?main.xml程序清单

Main.xml代码
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <TextView?xmlns:android="http://schemas.android.com/apk/res/android"??
  3. ????android:id="@+id/hello_world"?android:layout_width="fill_parent"??
  4. ????android:layout_height="fill_parent"?android:gravity="center_vertical|center_horizontal"??
  5. ????android:text="@string/hello_world"?/>??
<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android"	android:id="@+id/hello_world" android:layout_width="fill_parent"	android:layout_height="fill_parent" android:gravity="center_vertical|center_horizontal"	android:text="@string/hello_world" />

?

???R.java程序清单 —— res目录下的任何一个配置修改后,该文件会自动修改,这就是mvc模式的好处,一旦model修改,view也相应的改变,这就是mvc的优势

R.java代码
  1. package?com.oristand;??
  2. ??
  3. public?final?class?R?{??
  4. ????public?static?final?class?attr?{??
  5. ????}??
  6. ????public?static?final?class?drawable?{??
  7. ????????public?static?final?int?icon=0x7f020000;??
  8. ????}??
  9. ????public?static?final?class?id?{??
  10. ????????public?static?final?int?hello_world=0x7f050000;??
  11. ????}??
  12. ????public?static?final?class?layout?{??
  13. ????????public?static?final?int?main=0x7f030000;??
  14. ????}??
  15. ????public?static?final?class?string?{??
  16. ????????public?static?final?int?app_name=0x7f040001;??
  17. ????????public?static?final?int?hello_world=0x7f040000;??
  18. ????}??
  19. }??
package com.oristand;public final class R {    public static final class attr {    }    public static final class drawable {        public static final int icon=0x7f020000;    }    public static final class id {        public static final int hello_world=0x7f050000;    }    public static final class layout {        public static final int main=0x7f030000;    }    public static final class string {        public static final int app_name=0x7f040001;        public static final int hello_world=0x7f040000;    }}

?

?? string.xml程序清单

String.xml代码
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <resources>??
  3. ????<string?name="hello_world">Hello?World!</string>??
  4. ????<string?name="app_name">HelloWorldDemo</string>??
  5. </resources>??
<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello_world">Hello World!</string>    <string name="app_name">HelloWorldDemo</string></resources>

?
?? AndroidManifest.xml程序清单

Androidmanifest.xml代码
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <manifest?xmlns:android="http://schemas.android.com/apk/res/android"??
  3. ??????package="com.oristand"??
  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=".HelloWorldActivity"??
  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>???
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.oristand"      android:versionCode="1"      android:versionName="1.0.0">    <application android:icon="@drawable/icon" android:label="@string/app_name">        <activity android:name=".HelloWorldActivity"                  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></manifest> 

?

?运行配置

?

运行结果:

  相关解决方案