1 / 54

ANDROID PROGRAMMING1

ANDROID PROGRAMMING1. OUTLINE. Android 程式開發 專案架構 XML Dialog Toast Menu. 開發 ANDROID 的基本步驟. 程式規劃 & 架構設計 Project 包含哪些功能 需要哪些畫面 & 畫面間的流轉 需要之資料 & 其來源和格式 伺服器端支援 ? Database 的功能 ? 特殊權限 ? 後端服務 (Server)?. How to do it?. 把需要之介面畫出 ( 包含介面內包含之資訊及功能 ) 。 釐清每個介面的轉跳關係。

candy
Download Presentation

ANDROID PROGRAMMING1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ANDROID PROGRAMMING1

  2. OUTLINE • Android程式開發 • 專案架構 • XML • Dialog • Toast • Menu

  3. 開發ANDROID的基本步驟 程式規劃&架構設計 • Project包含哪些功能 • 需要哪些畫面&畫面間的流轉 • 需要之資料&其來源和格式 • 伺服器端支援? • Database的功能? • 特殊權限? • 後端服務(Server)?

  4. How to do it? • 把需要之介面畫出(包含介面內包含之資訊及功能)。 • 釐清每個介面的轉跳關係。 • 釐清資料是取自網路或本機或..,資料的存取較適用database或file。 • 後端服務需要長駐或只需在啟動時在後端執行,功能需要的權限。

  5. 程式開發步驟 • 實現UI(版面配置模式&介面元件) • 資料操作及儲存(資料來源&儲存方式) • 實現多頁面跳轉 ex:選取選單項目來跳轉, 監聽事件發生的處理 如果跳轉暫時無法連結 → add a button • Add server • 完善程式細節ex:程式需從網路取得資料 → AndroidManifest.xml加入相關uses-permission, 舊版本更新要加入Android : version code & Android version name

  6. 測試&發佈程式 • 使用模擬器(利用模擬器&控制面板) ex:DDMS(偵錯監視服務Dalvik Debug Monitor ServiceDalvik)是 SDK 自帶的一個可視的偵錯工具。提供螢幕截圖、日誌存儲和行程檢測能力。 打包、產生簽暑金鑰檔案 • 可以發佈到Android Market

  7. API查詢 http://developer.android.com/reference/packages.html

  8. 專案架構 • src/ :原始碼(source)目錄,放置.java檔 • gen/:自動生成(generate)目錄,內部檔案自動生成 • R.java:資源列表,包含使用者介面、圖像、字串,程式中用到的資源都會在這裡自動產生列表。 • res/:資源(resouce)目錄,存放資料檔案、圖片、xml檔 • layout/ :xml介面描述檔 • values/:xml格式的參數值描述檔 • drawable/:用到的圖片 • AndroidManifest.xml:應用程式功能清單

  9. XML 描述使用者介面 res/layout/main.xml • 將介面顯示與程式邏輯分離ex. 哪裡顯示文字,哪裡顯示按鈕 • 程式的由此檔案描述

  10. XML檔 • XML (Extensible Markup Language) 是一種標記描述語言,不管是語法還是看起來的樣子,都相當類似網頁所使用的 HTML 標記語言。 • XML 被廣泛地運用在 Java 程式的設定中。「main.xml」 文件裡,第一行是每個 XML 描述檔固定的開頭內容,用來指示這個文字檔案是以 XML格式描述的。

  11. 表示xml的版本、編碼方式 res/layout/main.xml <?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:layout_width="fill_parent"             android:layout_height="wrap_content"           android:text="@string/hello"           />    </LinearLayout>

  12. LinearLayout (線性版面配置) res/layout/main.xml <?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:layout_width="fill_parent"             android:layout_height="wrap_content"           android:text="@string/hello"           /></LinearLayout> FrameLayout (框架版面配置) TableLayout (表格版面配置) AbsoluteLayout (絕對位置版面配置) RelativeLayout (相對位置版面配置)

  13. res/layout/main.xml <?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:layout_width="fill_parent"             android:layout_height="wrap_content"           android:text="@string/hello"           />    </LinearLayout> 走向 介面寬度 介面長度

  14. res/layout/main.xml <?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:layout_width="fill_parent"             android:layout_height="wrap_content"           android:text=" Hello World, Bmi!”            />    </LinearLayout> 是顯示文字到螢幕上

  15. VIEW • 顯示介面類ex. 文字、按鈕、輸入欄位 • 版面配置類ex. Layout、Tab • 狀態提示類ex. 進度條、等待圈

  16. BMI程式 • BMI值=體重(kg) / 身高(m)^2

  17. MAIN.XML <TextViewandroid:layout_width="fill_parent“android:layout_height="wrap_content“android:text="身高 (cm)“/><EditText android:id="@+id/height“    android:layout_width="fill_parent“    android:layout_height="wrap_content“android:numeric="integer"    android:text="" 「android:phoneNumber=“true”」 僅允許輸入電話號碼 「android:autoLink=“all”」 自動將文字轉成超連結 「android:numeric=“true”」 限制使用者只能輸入數字

  18. MAIN.XML <TextView android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:text="體重 (kg)"    />      <EditText android:id="@+id/weight"    android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:numeric="integer"     android:text=""    />

  19. MAIN.XML <Button android:id="@+id/submit"            android:layout_width="fill_parent"            android:layout_height="wrap_content"android:text="計算 BMI 值"/><TextView android:id="@+id/result"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text=""            />             <TextView android:id="@+id/suggest"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:text=""

  20. 將字串抽離 XML • res/values/strings.xml <?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">BMI</string>    <string name="bmi_height">身高 (cm)</string>    <string name="bmi_weight">體重 (kg)</string>    <string name="bmi_btn">計算 BMI 值</string>    <string name="bmi_result">你的 BMI 值是 </string></resources> <string name="識別代號">文字敘述</string>

  21. 存取識別符號 @[類型]/[識別符號] <EditText android:id="@+id/height”  /> • XML占空間 • Android 並不直接使用 XML 檔案,而是透過 Android 開發工具,自動將 XML 描述檔轉換成資源檔案。一旦應用程式要操作某個介面元件,或是使用任何種類的資源(字串、圖片、圖示、音效...),都使用索引來查詢。

  22. 屬性 R.java     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 height=0x7f050000;            public static final int result=0x7f050003;            public static final int submit=0x7f050002;            public static final int suggest=0x7f050004;            public static final int weight=0x7f050001;        }        public static final class layout {            public static final int main=0x7f030000;        }        public static final class string {            public static final int app_name=0x7f040000;        }    } 圖片 識別符號 介面描述 文字

  23. BEFORE <TextViewandroid:layout_width=“fill_parent“android:layout_height=”wrap_content“android:text=”身高 (cm)“/> <string name="bmi_height">身高 (cm)</string> AFTER <TextView         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="@string/bmi_height"        />

  24. .JAVA 專案開啟時已經寫好了

  25. package test.BMI; import android.app.Activity; import android.os.Bundle; public class BMI extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

  26. package test.BMI; import android.app.Activity; import android.os.Bundle; public class BMI extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

  27. package test.BMI; import android.app.Activity; import android.os.Bundle; public class BMI extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } 與記憶體管理有關

  28. package test.BMI; import android.app.Activity; import android.os.Bundle; public class BMI extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

  29. package test.BMI; import android.app.Activity; import android.os.Bundle; public class BMI extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

  30. BMI.JAVA

  31. BMI.JAVA

  32. 觸發事件函式

  33. 編輯欄位

  34. 運算

  35. 顯示結果

  36. 格式

  37. 顯示建議

  38. DIALOG

  39. OPENOPTIONSDIALOG()函式內容 建立了一個 AlertDialog 對話框類別實體

  40. 最後一定要顯示

  41. DIALOG加入按鈕 沒做事結束對話框

  42. TOAST

  43. 顯示時間長短

  44. MENU

  45. 建立選單 處理選項動作

  46. 建立選單

More Related