엑티비티 이동 소스를 붙여넣고 page1.java 에다가 버튼&이미지 소스를 붙여 넣고 Android Manifest 에도 등록 했고
오류도 안났어요
Page1.java
package skan.skanteam.koveaskan;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class page1 extends Activity implements OnClickListener {
Button bt, bt2, bt3, bt4;
ImageView iv;
TextView tv;
/** Called when the activity is first created. */
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//해당하는 xml파일 명으로 바꿔야함
// xml에 불러온 이미뷰를 bt에 넣어 속성사용 하기위한 구문
bt = (Button) findViewById(R.id.button1);
bt2 = (Button) findViewById(R.id.button2);
bt3 = (Button) findViewById(R.id.button3);
bt4 = (Button) findViewById(R.id.button4);
// 버튼에 클릭이벤트 처리
bt.setOnClickListener(this);
bt2.setOnClickListener(this);
bt3.setOnClickListener(this);
bt4.setOnClickListener(this);
// xml에 불러온 이미뷰를 iv에 넣어 속성사용 하기위한 구문
iv = (ImageView) findViewById(R.id.imageView1);
// xml에 불러온 텍스트뷰를 tv에 넣어 속성사용 하기위한 구문
tv = (TextView) findViewById(R.id.textView1);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.button1:
// 이미지뷰에 사진을 출력하는 구문
iv.setImageResource(R.drawable.test1);
// 텍스트뷰에 문자열 출력하는 구문
tv.setText("test1 사진");
break;
case R.id.button2:
iv.setImageResource(R.drawable.test2);
tv.setText("test2 사진");
break;
case R.id.button3:
iv.setImageResource(R.drawable.test3);
tv.setText("test3 사진");
break;
case R.id.button4:
iv.setImageResource(R.drawable.test4);
tv.setText("test4 사진");
break;
}
}
}
Page1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"></Button>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"></Button>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"></Button>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"></Button>
</LinearLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="300dp"></ImageView>
<TextView
android:text="TextView"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:layout_gravity="center"></TextView>
</LinearLayout>