안드로이드 세미나 2
Upcoming SlideShare
Loading in...5
×
 

안드로이드 세미나 2

on

  • 597 views

간단한 안드로이드 세미나 2

간단한 안드로이드 세미나 2

Statistics

Views

Total Views
597
Views on SlideShare
597
Embed Views
0

Actions

Likes
1
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

안드로이드 세미나 2 안드로이드 세미나 2 Presentation Transcript

  • ANDROID 세미나FOR BEGINNER (2) PoolC 홍철주 2012. 4. 18
  • 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>
  • RESOURCE -> SOURCE CODE
  • 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); } }
  • RESOURCE -> SOURCE CODE public 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; } }
  • RESOURCE -> SOURCE CODE {ResourceType} {Varible} = (ResourceType)findViewById(ResourceAddress);
  • 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(); } });
  • ACTIVITY• 일단은 보이는 화면이라고 생각• 당신은 화면 위에다가 터치도 하고 이것 저것한다 • 입력도 받고 출력도 받고• 액티비티 주기를 볼 필요가 있긴 한데...
  • INTENT• 안드로이드에서의 의사표현 수단• 어떤 component를 부른다!• 그리고 무엇을 해달라고 요청!
  • CONTEXT• 어플리케이션 환경의 전역 정보에 접근하기 위한 인터페이스• 시스템 정보 접근, API 호출• 액티비티간 리소스 공유 등..
  • INTENT -> NEW ACTIVITY! Intent mIntent = new Intent(TestActivity.this, SecondActivity.class); startActivity(mIntent); Intent 의 생성자는 여러가지. 이는 그 중 하나.
  • SIMPLE CALCULATOR op1opr op2 result
  • SIMPLE CALCULATOR EditText op1, op2; TextView opr, result; Button plus, minus, mul, div;
  • 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? -> activitypublic class TestActivity extends Activity implements View.OnClickListener
  • 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; } }
  • 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));