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>

 --------------------------------
然後是Button建置步驟:

1.建立Layout: /res/layout/main.xml
–<Button android:id=“@+id/btn_Button” />
2.Main app
–onCreate()
•findViewById(R.id.btn_Button)
•SetOnClickListener()
–onClick()
–Intent(): setClass(this, .class)
–startActivity()
3.Sub app layout: /res/layout/sub_app.xml
4.Sub app code:
–onCreate()
•findViewById(R.id.btn_Click)
•SetOnClickListener()
–onClick()
–setTitle()
5.AndroidManifest.xml
–宣告application的設定值

留言