1 / 46

LifecareScienceLAB Android Seminar 3 rd class

아주대학교. LifecareScienceLAB Android Seminar 3 rd class. Android Software Development 2011/05/04 – p.m. 06:00 – 팔달관 409 호. Review. User Interface Button, TextView , EditText LinearLayout Software Design Tool. Widget. TextView , Button, EditText 를 이용하여 버튼을 누르면 편집한 문자열이 출력되는 예제

sook
Télécharger la présentation

LifecareScienceLAB Android Seminar 3 rd class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 아주대학교 LifecareScienceLABAndroid Seminar 3rd class Android Software Development 2011/05/04 – p.m. 06:00 – 팔달관 409호

  2. Review • User Interface • Button, TextView, EditText • LinearLayout • Software Design Tool

  3. Widget • TextView, Button, EditText를 이용하여 버튼을 누르면 편집한 문자열이 출력되는 예제 main.xml→

  4. Widget ↓ Activity Class

  5. State Diagram Play Pause Playing Stop Play Not Playing, At the beginning Stop Play Pause Pause Stop Paused

  6. Structure Chart sub process 1 process sub process 2 main Input sub process 3 ouput print

  7. Flow Chart New Stage START Button Input Add Random Value to Array LED Output Array Size + 1 i < Array Size? i < Array Size? i <= 0 i <= 0 False False Turn on All LED i++ i++ Array[i] == Input? True True Input Data from Button Output Data in Array[i] to LED Turn on All LED False Clear Array Array Size <= 0 i <= 0 True

  8. Class Diagram Uses▶ Director Builder Main builder makeTitle makeString makeItems close construct HTMLBuilder TextBuilder filename writer buffer makeTitle makeString makeItems close getResult makeTitle makeString makeItems close getResult Uses▲ Uses▲

  9. Sequence Diagram :Client :Server :Device work open print write close

  10. Contents List

  11. Activity • Toast • Log ANdroid

  12. Activity • 프로그램에서의 “화면 하나” • 반드시 “View”나 “View Group”를가져야 한다. • 액티비티는 서로 중첩되지 않으며 독립적이다.(View는 중첩된다.)

  13. Activity LifeCycle

  14. Activity 추가 MainActivity.java Activity mainactivity.xml View SubActivity.java Activity subactivity.xml View

  15. 프로젝트 생성 Create Activity : MainActivity→

  16. main.xml 파일 이름 바꾸기

  17. main.xml 파일 이름 바꾸기

  18. SubActivity Class 추가하기

  19. SubActivity Class 추가하기

  20. subactivity xml 파일 추가하기

  21. subactivity xml 파일 추가하기

  22. AndroidManifest파일에 등록하기

  23. AndroidManifest파일에 등록하기

  24. AndroidManifest파일에 등록하기

  25. AndroidManifest파일에 등록하기

  26. AndroidManifest파일에 등록하기

  27. AndroidManifest파일에 등록하기

  28. AndroidManifest파일에 등록하기

  29. AndroidManifest파일에 등록하기

  30. MainActivity.java • import android.app.Activity; • import android.content.Intent; • import android.os.Bundle; • import android.view.View; • import android.view.View.OnClickListener; • import android.widget.Button; • public class MainActivity extends Activity { • /** Called when the activity is first created. */ • @Override • public void onCreate(Bundle savedInstanceState) { • super.onCreate(savedInstanceState); • setContentView(R.layout.mainactivity); • Button btnCall = (Button)findViewById(R.id.call); • btnCall.setOnClickListener(new OnClickListener(){ • public void onClick(View v){ • Intent intent = new Intent(MainActivity.this, SubActivity.class); • startActivity(intent); • } • }); • } • }

  31. mainactivity.xml • <?xml version="1.0" encoding="utf-8"?> • <LinearLayoutxmlns: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:text="메인 엑티비티입니다." • android:textSize="30dp" • android:textColor="#FF0000" • ></TextView> • <Button • android:layout_width="wrap_content" • android:layout_height="wrap_content" • android:id="@+id/call" • android:text="Call" • ></Button> • </LinearLayout>

  32. SubActivity.java • import android.app.Activity; • import android.os.Bundle; • import android.view.View; • import android.view.View.OnClickListener; • import android.widget.Button; • public class SubActivity extends Activity { • /** Called when the activity is first created. */ • @Override • public void onCreate(Bundle savedInstanceState) { • super.onCreate(savedInstanceState); • setContentView(R.layout.subactivity); • Button btnClose = (Button)findViewById(R.id.close); • btnClose.setOnClickListener(new OnClickListener(){ • public void onClick(View v){ • finish(); • } • }); • } • }

  33. subactivity.xml • <?xml version="1.0" encoding="utf-8"?> • <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" • android:layout_width="fill_parent" • android:layout_height="fill_parent" • android:orientation="vertical" • > • <TextView • android:layout_height="wrap_content" • android:layout_width="fill_parent" • android:text="메인에서 호출한 서브입니다." • android:textSize="20dp" • android:textColor="#00FF00" • ></TextView> • <Button • android:layout_width="wrap_content" • android:layout_height="wrap_content" • android:id="@+id/close" • android:text="Close" • ></Button> • </LinearLayout>

  34. Activity간의 통신 • 인텐트는액티비티간에 인수와 리턴값을 전달하는 도구로도 사용된다. • 값을 저장하는 Method • Intent putExtra(String name, int value) • Intent putExtra(String name, String value) • Intent putExtra(String name, boolean value) • 저장된 값을 꺼내오는 Method • intgetIntExtra(String name, intdefaultValue) • String getStringExtra(String name) • booleangetBooleanExtra(String name, booleandefaultValue) • 리턴값을 돌려받기 위해 누가 호출했는지 알려주는 Method • public void startActivityForResult(Intent intent, intrequestCode) • 리턴값을 돌려받는 Method • Protected void onActivityResult(intrequestCode, intresultCode, Intent data)

  35. Activity간의 통신 CommActivity.java Activity main.xml View ActEdit.java Activity sub.xml View

  36. CommActivity.java • import android.app.*; • import android.content.*; • import android.os.*; • import android.view.*; • import android.widget.*; • public class CommActivity extends Activity { • TextViewmText; • final static intACT_EDIT = 0; • public void onCreate(Bundle savedInstanceState) { • super.onCreate(savedInstanceState); • setContentView(R.layout.main); • mText = (TextView)findViewById(R.id.textView); • Button btnEdit=(Button)findViewById(R.id.buttonNEXT); • btnEdit.setOnClickListener(new Button.OnClickListener() { • public void onClick(View v) { • Intent intent = new Intent(CommActivity.this, ActEdit.class); • intent.putExtra("TextIn", mText.getText().toString()); • startActivityForResult(intent,ACT_EDIT); • } • }); • } • protected void onActivityResult (intrequestCode, intresultCode, Intent data) { • switch (requestCode) { • case ACT_EDIT: • if (resultCode == RESULT_OK) { • mText.setText(data.getStringExtra("TextOut")); • } • break; • } • } • }

  37. main.xml • <?xml version="1.0" encoding="utf-8"?> • <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" • android:orientation="vertical" • android:layout_width="fill_parent" • android:layout_height="fill_parent" • > • <TextView • android:text="TextView" • android:layout_height="wrap_content" • android:id="@+id/textView" • android:textSize="30dp" • android:layout_width="fill_parent" • ></TextView> • <Button • android:layout_height="wrap_content" • android:id="@+id/buttonNEXT" • android:text="EDIT" • android:layout_width="fill_parent" • android:textSize="20dp" • ></Button> • </LinearLayout>

  38. ActEdit.java • import android.app.*; • import android.content.*; • import android.os.*; • import android.view.*; • import android.widget.*; • public class ActEdit extends Activity { • EditTextmEdit; • public void onCreate(Bundle savedInstanceState) { • super.onCreate(savedInstanceState); • setContentView(R.layout.sub); • mEdit = (EditText)findViewById(R.id.editText); • Intent intent = getIntent(); • mEdit.setText(intent.getStringExtra("TextIn")); • Button btnOK=(Button)findViewById(R.id.buttonOK); • btnOK.setOnClickListener(new Button.OnClickListener() { • public void onClick(View v) { • Intent intent = new Intent(); • intent.putExtra("TextOut", mEdit.getText().toString()); • setResult(RESULT_OK,intent); • finish(); • } • }); • Button btnCancel=(Button)findViewById(R.id.buttonCANCEL); • btnCancel.setOnClickListener(new Button.OnClickListener() { • public void onClick(View v) { • setResult(RESULT_CANCELED); • finish(); • } • }); • } • }

  39. sub.xml • <?xml version="1.0" encoding="utf-8"?> • <LinearLayout • xmlns:android="http://schemas.android.com/apk/res/android" • android:layout_width="fill_parent" • android:layout_height="fill_parent" android:orientation="vertical"> • <EditText • android:text="EditText" • android:layout_height="wrap_content" • android:id="@+id/editText" • android:layout_width="fill_parent" • android:textSize="30dp" • ></EditText> • <Button • android:layout_height="wrap_content" • android:id="@+id/buttonOK" • android:text="OK" • android:layout_width="fill_parent" • android:textSize="20dp" • ></Button> • <Button • android:layout_height="wrap_content" • android:id="@+id/buttonCANCEL" • android:text="CANCEL" • android:layout_width="fill_parent" • android:textSize="20dp" • ></Button> • </LinearLayout>

  40. Activity간의 통신 CommActivity.java Activity ActEdit.java Activity new intent +Caller, +Callee getIntent TextIn getStringExtra TextIn putExtra +TextIn new intent startActivityForResult putExtra +TextOut onActivityResult setResut getStringExtra TextOut TextOut

  41. Toast • 작은 팝업 대화상자 • 초보자들에게 디버깅용, 학습용으로 아주 용이한 출력 방법 • 변수 값을 수시로 찍어볼 때 등

  42. Toast • 생성 Method • static Toast makeToast(Context context, intresId, int duration) • context : 메시지를 출력하는 주체 • MainActivity.this • resId : 출력할 문자열의 ID • R.String.name • duration : 메시지 출력 지속시간 • LENGTH_SHORT, LENGTH_LONG • static Toast makeToast(Context context, CharSequence text, int duration) • text : 출력할 메시지 • “LifecareScienceLAB” • 옵션 Method • void setGravity(int gravity, int, xOffset, intyOffset) • void setMargin(float horizonMargin, float verticalMargin) • void setText(CharSequence s) • void setDuration(int duration) • void setView(View view) • 메시지를 보이거나 숨기는 Method • void show() • void cancel()

  43. ToastTest.java • import android.app.*; • import android.os.*; • import android.view.*; • import android.widget.*; • import exam.AndroidExam.*; • public class ToastTest extends Activity { • Toast mToast = null; • int count; • String str; • public void onCreate(Bundle savedInstanceState) { • super.onCreate(savedInstanceState); • setContentView(R.layout.main); • findViewById(R.id.shortmsg).setOnClickListener(mClickListener); • findViewById(R.id.longmsg).setOnClickListener(mClickListener); • findViewById(R.id.count1).setOnClickListener(mClickListener); • findViewById(R.id.count2).setOnClickListener(mClickListener); • findViewById(R.id.customview).setOnClickListener(mClickListener); • } • Button.OnClickListenermClickListener = new Button.OnClickListener() { • public void onClick(View v) { • switch (v.getId()) { • case R.id.shortmsg: • Toast.makeText(ToastTest.this, "잠시 나타나는 메시지", • Toast.LENGTH_SHORT).show(); • break; • case R.id.longmsg: • Toast.makeText(ToastTest.this, "조금 길게 나타나는 메시지", • Toast.LENGTH_LONG).show(); • break; • case R.id.count1: • str = "현재 카운트 = " + count++; • if (mToast != null) { • mToast.cancel(); • } • mToast = Toast.makeText(ToastTest.this, str, Toast.LENGTH_SHORT); • mToast.show(); • break; • case R.id.count2: • str = "현재 카운트 = " + count++; • if (mToast == null) { • mToast = Toast.makeText(ToastTest.this, str, Toast.LENGTH_SHORT); • } else { • mToast.setText(str); • } • mToast.show(); • break; • case R.id.customview: • LinearLayout linear = (LinearLayout)View.inflate(ToastTest.this, • R.layout.output_toast, null); • Toast t2 = new Toast(ToastTest.this); • t2.setView(linear); • t2.show(); • break; • } • } • }; • }

  44. main.xml • <?xml version="1.0" encoding="utf-8"?> • <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" • android:orientation="vertical" • android:layout_width="fill_parent" • android:layout_height="fill_parent" • > • <Button • android:id="@+id/shortmsg" • android:layout_width="fill_parent" • android:layout_height="wrap_content" • android:text="짧은 메시지" • /> • <Button • android:id="@+id/longmsg" • android:layout_width="fill_parent" • android:layout_height="wrap_content" • android:text="긴 메시지" • /> • <Button • android:id="@+id/count1" • android:layout_width="fill_parent" • android:layout_height="wrap_content" • android:text="카운트 연속 출력" • /> • <Button • android:id="@+id/count2" • android:layout_width="fill_parent" • android:layout_height="wrap_content" • android:text="카운트 연속 출력2" • /> • <Button • android:id="@+id/customview" • android:layout_width="fill_parent" • android:layout_height="wrap_content" • android:text="커스텀뷰 표시" • /> • </LinearLayout>

  45. Log • 개발자를 위한 디버깅용 메시지 • Eclipse를 통해서만 확인 가능 • LogCat을 이용하여 확인 할 수 있다. • 다양한 메시지 필터 • Log.v : verbose • Log.i : information • Log.w : warning • Log.e : error • Log.d : debugging • Log.x(String tag, String msg) • tag : 사용자 정의 메시지 분류 • msg : 출력할 메시지

  46. Design Presentation Software Development

More Related