(1) 打開Android模擬器(AVDM),
(2) Device Definitions 選擇 2.7" QVGA, Create AVD
(3) Skin選擇HVGA
(4) 在AVDM (Android Virtual Device Manager)按Start
(5) 在Eclipse建立一個新的Android專案
https://developer.android.com/training/basics/firstapp/creating-project.html(6) 在Eclipse中, Run->Run Configurations->Android Application->Run
(7) 在模擬器中看App的執行
======
( 8 ) 打開 /res/layout/activity_main.xml
( 9 ) 在Graphical layout 刪除 TextView hello_world
(10 ) 拉一個 EditText(abc) Button 和 TextView(Large Text), 到Graphical layout
(11 ) 在 activity_main.xml Tab, 修改
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginLeft="0dp"
android:layout_marginTop="20dp"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="20dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
(12 ) 打開 res/values/strings.xml
(13 ) 插入下面三行
<string name="place_holder">xxxx</string>
<string name="app_func">查詢掛號</string>
(14 ) 修改activity_main.xml
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:ems="10"
android:inputType="text" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginLeft="0dp"
android:layout_marginTop="20dp"
android:text="@string/app_func" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="20dp"
android:text="@string/place_holder"
android:textAppearance="?android:attr/textAppearanceLarge" />
(15 ) 在<Button 改成:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginLeft="0dp"
android:layout_marginTop="20dp"
android:onClick="showMessage"
android:text="@string/app_func" />
(16) 在/src/com/example/mysecondapp/MainActivity.java,加上
public void showMessage(View view) {
}
(17 ) 在showMessage(View view) ,加上
TextView textView = (TextView) findViewById(R.id.textView1);
EditText editText = (EditText) findViewById(R.id.editText1);
String str = editText.getText().toString();
textView.setText(str);
(18 ) 在Eclipse中, Run->Run Configurations->Android Application->Run
(19 ) 在模擬器中看MyFirstApp的執行