Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수.

Similar presentations


Presentation on theme: "UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수."— Presentation transcript:

1 UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수

2 학습 목표 Image / Text 변경 Event Listener

3 글자를 바꾼다 public final void setText(CharSequence text) TextView tvPage;
@Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvPage = (TextView)findViewById(R.id.tvPage); tvPage.setText("1"); }

4 글자를 바꾼다 : String Resource
public final void setText(int resid) TextView tvPage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvPage = (TextView)findViewById(R.id.tvPage); tvPage.setText(R.string.page); }

5 그림을 바꾼다 public setImageResource(int resId) TextView tvPage;
ImageView ivBook; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvPage = (TextView)findViewById(R.id.tvPage); tvPage.setText(R.string.page); ivBook =(ImageView)findViewById(R.id.ivBook); ivBook.setImageResource(R.drawable.p02); }

6 실습 1: Layout 연결 및 초기화 Image View 를 연결하고 초기화
ImageView : 첫번째 Page Button , TextView 를 연결하고 초기화 Button : 이전 TextView : 1 Button : 다음

7 Event Listener 사용자의 입력이나 View 안에서 발생하는 Event를 Activity 에 전달하기 위한 Listener 방법 Call back Method Inner Class Anonymous Class

8 OnClickListener : Interface
public class MainActivity extends Activity implements View.OnClickListener { TextView tvPage; ImageView ivBook; Button btnPre; Button btnNext; int pageNumber = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvPage = (TextView)findViewById(R.id.tvPage); tvPage.setText("" + pageNumber); ivBook =(ImageView)findViewById(R.id.ivBook); ivBook.setImageResource(R.drawable.p02); btnPre = (Button)findViewById(R.id.btnPre); btnNext = (Button)findViewById(R.id.btnNext); btnPre.setOnClickListener(this); } public void onClick(View v) {

9 OnClickListener : inner class
public class MainActivity extends Activity { TextView tvPage; ImageView ivBook; Button btnPre; Button btnNext; int pageNumber = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvPage = (TextView)findViewById(R.id.tvPage); tvPage.setText("" + pageNumber); ivBook =(ImageView)findViewById(R.id.ivBook); ivBook.setImageResource(R.drawable.p02); btnPre = (Button)findViewById(R.id.btnPre); btnNext = (Button)findViewById(R.id.btnNext); BtnClickListener btnListener = new BtnClickListener(); btnPre.setOnClickListener(btnListener); } private class BtnClickListener implements View.OnClickListener { public void onClick(View v) {

10 OnClickListener : Anonymous Class
public class MainActivity extends Activity { TextView tvPage; ImageView ivBook; Button btnPre; Button btnNext; int pageNumber = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvPage = (TextView)findViewById(R.id.tvPage); tvPage.setText("" + pageNumber); ivBook =(ImageView)findViewById(R.id.ivBook); ivBook.setImageResource(R.drawable.p02); btnPre = (Button)findViewById(R.id.btnPre); btnNext = (Button)findViewById(R.id.btnNext); btnPre.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { } });

11 onClick 에서 View 처리 public class MainActivity extends Activity implements View.OnClickListener { TextView tvPage; ImageView ivBook; Button btnPre; Button btnNext; int pageNumber = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvPage = (TextView)findViewById(R.id.tvPage); tvPage.setText("" + pageNumber); ivBook =(ImageView)findViewById(R.id.ivBook); ivBook.setImageResource(R.drawable.p02); btnPre = (Button)findViewById(R.id.btnPre); btnNext = (Button)findViewById(R.id.btnNext); btnPre.setOnClickListener(this); } public void onClick(View v) { switch (v.getId()) { case R.id.btnNext: break; case R.id.btnPre:

12 실습 이전/다음 버튼 동작에 따른 이미지 및 Page 변경


Download ppt "UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수."

Similar presentations


Ads by Google