1.
<
TextView
2.
android:id
=
"@+id/text"
3.
android:layout_width
=
"fill_parent"
4.
android:layout_height
=
"wrap_content"
5.
/>
1.
TextView t = (TextView)findViewById(R.id.text);
2.
t.setText(
"Hello"
);
3.
t.setBackgroundColor(
0xFFFF0000
);
4.
t.setGravity(Gravity.LEFT);
1.
Button button = (Button)findViewById(R.id.button);
2.
button.setOnClickListener(
new
View.OnClickListener() {
3.
public
void
onClick(View v) {
4.
//Code
5.
}
6.
});
01.
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02.
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
03.
android:orientation
=
"vertical"
04.
android:layout_width
=
"fill_parent"
05.
android:layout_height
=
"fill_parent"
06.
>
07.
<
TextView
08.
android:id
=
"@+id/text"
09.
android:layout_width
=
"fill_parent"
10.
android:layout_height
=
"wrap_content"
11.
android:text
=
""
12.
/>
13.
<
Button
14.
android:id
=
"@+id/button"
15.
android:layout_width
=
"fill_parent"
16.
android:layout_height
=
"wrap_content"
17.
android:text
=
"버튼"
18.
/>
19.
</
LinearLayout
>
01.
package
kr.mobileplace.lecture;
02.
import
android.app.Activity;
03.
import
android.os.Bundle;
04.
import
android.view.Gravity;
05.
import
android.view.View;
06.
import
android.widget.Button;
07.
import
android.widget.TextView;
08.
public
class
MyActivity
extends
Activity {
09.
@Override
10.
protected
void
onCreate(Bundle savedInstanceState) {
11.
super
.onCreate(savedInstanceState);
12.
setContentView(R.layout.myactivity);
13.
Button button = (Button)findViewById(R.id.button);
14.
button.setOnClickListener(
new
View.OnClickListener() {
15.
public
void
onClick(View v) {
16.
TextView t = (TextView)findViewById(R.id.text);
17.
t.setText(
"클릭됨~"
);
18.
t.setBackgroundColor(
0xFFFF0000
);
19.
t.setGravity(Gravity.LEFT); }
20.
});
21.
}
22.
}