Code/Android

안드로이드 코드 작성법

sidcode 2010. 7. 28. 23:39
1. Hello Android 두가지 방법

 
 - 소스코드 직접 수정

public class hi extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        

        TextView t = new TextView(this);

 

        t.setText("Hello Sidcode!!!!");

        t.setTextSize(25);

        

        setContentView(t);

    }

}



- xml 수정
 - src/package/hi.java, 
   res/values/String.xml
   res/layout/main.xml

public class hi extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

    }

}

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <string name="hello">Hello Sidcode!</string>

    <string name="app_name">HelloSidcode</string>

</resources>

<?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:textSize="25sp"

    android:text="@string/hello"

    />

</LinearLayout>


주의: 절대 xml 부분에서 실행하지말라!!! 그지같은 경우가 발생한다...