第一個Android程式–Hello Android

來源:互聯網
上載者:User

原文: http://www.anddev.org/hello_android_-_your_first_application-t31.html

編寫第一個Android程式 "Hello Android" 

這是什麼: 這個教程示範如何建立最簡單的Android程式。
能學到什麼: 在Eclipse中建立一個Android工程,輸入代碼,建立回合組態。

難度: 0.5 of 5

最終效果:

具體步驟:
1. 首先,我們須建立一個新的工程,在Package-Explorer上空白地區右擊滑鼠。

2. 選擇"Android Project"

3. 填寫如下:

4. 這就是建立好的工程目錄結構(不要驚慌,其實大多數是些資源檔)

5. 找到並開啟"Hello_Android.java" 輸入如下代碼:

6. 開啟"Open Run Dialog..." 對話方塊

7. 設定如下,點Apply並點擊Run。

8. 模擬器啟動中。。。

9. 主程式在啟動。。。

10. 恭喜你,你的第一個程式運行起來了!


完整代碼

Java:
package org.anddev.android.Hello_Android; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class Hello_Android extends Activity ...{ 
    /** *//** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle icicle) ...{ 
        super.onCreate(icicle); 
        // We want to view some very simple text, so we need a TextView 
        TextView tv = new TextView(this); 
        // Put some text to the newly created TextVIew 
        tv.setText("Hello Android - by: anddev.org  " + 
               "This is soooo simple =D "); 
        // Tell our App to display the textView 
        this.setContentView(tv); 
    } 
}


 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.