Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Androidアプリのしくみ

@nekoruri
November 02, 2013

 Androidアプリのしくみ

Androidアプリのしくみ
(オブジェクト指向の基礎の基礎)

日本Androidの会 秋葉原支部
コスプレ理系女子普及部
第18回定例会 LT資料

@nekoruri

November 02, 2013
Tweet

More Decks by @nekoruri

Other Decks in Technology

Transcript

  1. public class MainActivity extends Activity { @Override protected void onCreate(Bundle

    savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } アプリを起動したら、 onCreateを呼ぶよ!
  2. public class MainActivity extends Activity { (onCreateは省略) public void onClick1(View

    v){ setContentView(R.layout.self_introduction); } } ボタンがクリックされたら onClick1を呼ぶよ! そしたら、setContentViewするよ!
  3. public class MainActivity extends Activity { TextView tv; public void

    onClick1(View v) { setContentView(R.layout.self_introduction); tv = (TextView) findViewById(R.id.textView1); tv.setText(“実はスポーツマン”); } ボタンがクリックされたら textView1の文字を 「実はスポーツマン」に変えるよ!
  4. public class MainActivity extends Activity { TextView tv; public void

    onClick1(View v) { setContentView(R.layout.self_introduction); tv = (TextView) findViewById(R.id.textView1); tv.setText(“実はスポーツマン”); } textView1を変数 tv に入れて、 tvのsetTextメソッドを呼ぶよ!
  5. public class MainActivity extends Activity { TextView tv; public void

    onClick1(View v) { setContentView(R.layout.self_introduction); tv = (TextView) findViewById(R.id.textView1); tv.setText(“実はスポーツマン”); } こんにちは! ボタン findViewByIdを使って、 Androidが作ってくれたインスタンスをさす 矢印を変数にいれます この矢印を通してメソッドを呼んで、 「命令」をインスタンスに送ります レイアウトファイル に従って作られた 画像やボタンの 「インスタンス」
  6. public class MainActivity extends Activity { TextView tv; public void

    onClick1(View v) { setContentView(R.layout.self_introduction); tv = (TextView) findViewById(R.id.textView1); tv.setText(“実はスポーツマン”); tv = (TextView) findViewById(R.id.textView2); tv.setText(“わたしの戦闘力は53万です。”); } こんにちは! ボタン 自己紹介
  7. public class MainActivity extends Activity { TextView tv; public void

    onClick1(View v) { setContentView(R.layout.self_introduction); tv = (TextView) findViewById(R.id.textView1); tv.setText(“実はスポーツマン”); tv = (TextView) findViewById(R.id.textView2); tv.setText(“わたしの戦闘力は53万です。”); } こんにちは! ボタン 自己紹介 同じ変数に 「別のインスタンスをさす矢印」 をいれなおすこともできます