안드로이드 세미나 2

16
ANDROID 세미나 FOR BEGINNER (2) PoolC 홍철주 2012. 4. 18

Upload: chul-ju-hong

Post on 22-Jun-2015

87 views

Category:

Technology


0 download

DESCRIPTION

만들다 만거 같다??

TRANSCRIPT

Page 1: 안드로이드 세미나 2

ANDROID 세미나FOR BEGINNER (2)

PoolC 홍철주

2012. 4. 18

Page 2: 안드로이드 세미나 2

RESOURCE -> SOURCE CODE

<?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" >

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" />

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout>

Page 3: 안드로이드 세미나 2

RESOURCE -> SOURCE CODE

Page 4: 안드로이드 세미나 2

RESOURCE -> SOURCE CODE

public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button mButton = (Button)findViewById(R.id.button1); }}

Page 5: 안드로이드 세미나 2

RESOURCE -> SOURCE CODEpublic final class R { public static final class attr { } public static final class drawable { public static final int ic_launcher=0x7f020000; } public static final class id { public static final int button1=0x7f050000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; }}

Page 6: 안드로이드 세미나 2

RESOURCE -> SOURCE CODE

{ResourceType} {Varible} = (ResourceType)findViewById(ResourceAddress);

Page 7: 안드로이드 세미나 2

RESOURCE -> SOURCE CODE

Button mButton = (Button)findViewById(R.id.button1); // Button Listener : onClick -> call a function mButton.setOnClickListener(new Button.OnClickListener(){

public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "Hello, World", Toast.LENGTH_SHORT).show(); } });

Page 8: 안드로이드 세미나 2

ACTIVITY

•일단은 보이는 화면이라고 생각

•당신은 화면 위에다가 터치도 하고 이것 저것한다

•입력도 받고 출력도 받고

•액티비티 주기를 볼 필요가 있긴 한데...

Page 9: 안드로이드 세미나 2

INTENT

•안드로이드에서의 의사표현 수단

•어떤 component를 부른다!

•그리고 무엇을 해달라고 요청!

Page 10: 안드로이드 세미나 2

CONTEXT

•어플리케이션 환경의 전역 정보에 접근하기 위한 인터페이스

•시스템 정보 접근, API 호출

•액티비티간 리소스 공유 등..

Page 11: 안드로이드 세미나 2

INTENT -> NEW ACTIVITY!

Intent mIntent = new Intent(TestActivity.this, SecondActivity.class); startActivity(mIntent);

Intent 의 생성자는 여러가지.이는 그 중 하나.

Page 12: 안드로이드 세미나 2

SIMPLE CALCULATOR

op1

op2

result

opr

Page 13: 안드로이드 세미나 2

SIMPLE CALCULATOR

EditText op1, op2; TextView opr, result; Button plus, minus, mul, div;

Page 14: 안드로이드 세미나 2

SIMPLE CALCULATOR

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); op1 = (EditText)findViewById(R.id.op1); op2 = (EditText)findViewById(R.id.op2); opr = (TextView)findViewById(R.id.opr); result = (TextView)findViewById(R.id.result); plus = (Button)findViewById(R.id.plus); plus.setOnClickListener(this); minus = (Button)findViewById(R.id.minus); minus.setOnClickListener(this); mul = (Button)findViewById(R.id.mul); mul.setOnClickListener(this); div = (Button)findViewById(R.id.div); div.setOnClickListener(this); } this? -> activity

public class TestActivity extends Activity implements View.OnClickListener

Page 15: 안드로이드 세미나 2

SIMPLE CALCULATOR

public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.plus: process(Operator.plus); break; case R.id.minus: process(Operator.minus); break; case R.id.mul: process(Operator.mul); break; case R.id.div: process(Operator.div); break; } }

Page 16: 안드로이드 세미나 2

SIMPLE CALCULATORvoid process(Operator op) { int op1Num = Integer.parseInt(op1.getText().toString()); int op2Num = Integer.parseInt(op2.getText().toString()); double resultNum = 0; switch(op) { case plus: resultNum = op1Num + op2Num; opr.setText("+"); break; case minus: resultNum = op1Num - op2Num; opr.setText("-"); break; case mul: resultNum = op1Num * op2Num; opr.setText("*"); break; case div: resultNum = (double)op1Num / op2Num; opr.setText("/"); break; } result.setText(Double.toString(resultNum)); }