1. MainActivity.java
package org.me.android_helloworld; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); //設定要使用的layout setContentView(R.layout.main); //取得TextView物件 TextView view = (TextView) findViewById(R.id.textView); view.setText("hellworld"); } }
2. 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:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout>
3. AndroidManifest.xml
<?xml version="1.0" encoding="UTF-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.me.android_helloworld"> <application> <activity android:name=".MainActivity" android:label="MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
4. 結果
沒有留言:
張貼留言