發表文章

目前顯示的是 5月, 2011的文章

Android Views and button textedit usage

圖片
今天要寫的程式是計算1+2+…+(n-1)+n=? 要用到的東西有: 1.edittext 2.button 很簡單的程式,重點是在如何取得user輸入的資料,以及edittext的使用. 首先,要先了解 TextView, EditText, and Button, the XML layout file (main.xml)格式: < 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/ txtDemo "     android:layout_width =" fill_parent "     android:layout_height =" wrap_content "     /> < EditText     android:id ="@+id/ eTxtDemo "     android:layout_width =" fill_parent "     android:layout_height =" wrap_content "     /> < Button     android:id ="@+id/ btnDone "     android:layout_width =" wrap_content "     android:layout_height =" wrap_content "     android:text ="Log it"     /> LinearLayout &g

Creating an Activity with intent

圖片
 [Intent Objects]   •用途:在兩個Activity之間跳轉時使用了Intent. •An Intent object is a bundle of information. •It contains information of interest to the component that receives the intent •Intent messaging is a facility for late run-time binding between components in the same or different applications. [Action & data ] The primary pieces of information in an intent: –action -- The general action to be performed, such as ACTION_VIEW , ACTION_EDIT , ACTION_MAIN . –data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri . [Intent type] •Explicit Intents have specified a component –via setComponent(ComponentName ) or setClass(Context , Class ) ) –用setClass來設置Intent的發起方與接收方. •Implicit Intents have not specified a component; –instead, they must include enough information for the system to determine which of the available components is best to run for that intent. –不需要用setClass或setComponent來指定事件處理器,利用AndroidMenifest.xml中的配置就可以由平臺定位事件

Use Ddms and add debug message in your application.

圖片
DDMS是開發Android所必備的debug tool,它的功能有: –Devices - Shows the list of devices and AVDs that are connected to ADB. –Emulator Control - Lets you carry out device functions. – LogCat - Lets you view system log messages in real time. – Threads - Shows currently running threads within a VM. –Heap - Shows heap usage for a VM. –Allocation Tracker - Shows the memory allocation of objects. – File Explorer - Lets you explore the device's file system. 紅色是最重要的功能. [ Using LogCat ] LogCat is integrated into DDMS, and outputs the messages that you print out using the Log class.  因為我們要debug程式,所以要了解其用法: •logcat messages type: – Verbose – Debug – Info – Warn – Error The Log class: – v(String , String) (verbose)  – d(String , String) (debug)  – i(String , String) (information)  – w(String , String) (warning)  – e(String , String) (error) For example: Log.i("MyActivity", "MyClass.getView() — get item number " + position); output : I/MyActiv

Create first android application

圖片
今天開始要練習建立第一個Android HelloWorld application, 但是我有一個疑問就產生了,這個 helloworld怎麼連system.out.println()都沒用就可以print? >> R.Java 的用途? 馬上請google大神查到了許多關於R.java的解釋:   •android的資源文件R.java: R->resource 資源文件 •有不可修改的提醒: /* AUTO-GENERATED FILE. DO NOT MODIFY. •R.java 根據 main.xml 自動產生,「並不是由程式設計師手動編寫」,請勿修改此檔案。 •This file is automatically generated by Android Developer Tools and "connects" the visual resources to the Java source code. •R.java是ADT自動生成的資源文件,不充許用戶編輯的,上面保存有各個資源的ID。它會保存在gen目錄下。 •Android自己維護這一個public final class R類主要是跟新資源文件,這個R.java無需我們自己去修改,如果你不瞭解千萬不要去修改它,它定義的每個資源值都是唯一的,不會和系統衝突。 •這個文件由ADT插件自動更新,當你編輯過Res文件後保存,這個類就會自動更新。 •R.java裡面一般有attr、drawable、id、raw、layout、string以及xml等,根據你工程使用的資源而定。 •當 R.java文件丟失時,就需要重建這個,但是可能會存在一些問題,比如資源無法自動更新。 •R.java 是由 Android Development Kit 所自動產生的資源索引檔(resource index),「R」是一個類別,這是 Android 應用程式資源的索引類別。「R.layout」類別則是 UI 佈局的索引類別,R.layout 類別裡的「main」成員就是 Android 應用程式的「主佈局索引」。 print function 在哪 ??? 1.主程式被執行,就會呼叫onCreate(), 執

寫android app with real connected phone

圖片
寫android最重要的是練習,但android模擬器實在是慢到爆,而且很多功能是無法用模擬出來的, 我特別去買了一隻android 2.2的手機來練習 step 1: 先把手機開啟 USB Debugging mode: On the device, go to home screen, press Menu , select Applications > Development , and enable  USB Debugging . 成功的把範例程式run在手機上.

開始發展Android

之前去某家公司面試時,當時那裡的主管問我說,你現在公司不是就有Android的team, 想往Android怎麼不在Pegatron加入Android的部門? 當時我回答不出來...因為我沒想到過... 當時只想要往android發展,卻沒有想到過這點.. 真是一語打醒夢中人阿, 今天5/9終於轉到Pegatron內的 Android的Team了, 以後每天可以專心發展Android相關程式,興趣跟工作相結合. 希望一年以後我能成為Android方面的專家.