1 / 19

PBL - ソフトウェア班 - 組み込みソフトウェアの開発 第三回

PBL - ソフトウェア班 - 組み込みソフトウェアの開発 第三回. 前回行ったこと. 画面を設計する ボタンを配置する レイアウトを変更する. 今回行うこと. ボタンの動作を設定. 何度かボタンを押す. 動作の設定. Android では, JAVA という言語を使って動作設定する. JAVA を説明する前に・・・ 実際にどういうものか見てみよう!!. 画面を設計 (XML) 1/3. 前回も編集した この場所にある XML を編集する. 画面を設計 (XML) 2/3.

scout
Download Presentation

PBL - ソフトウェア班 - 組み込みソフトウェアの開発 第三回

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. PBL -ソフトウェア班-組み込みソフトウェアの開発第三回

  2. 前回行ったこと • 画面を設計する • ボタンを配置する • レイアウトを変更する

  3. 今回行うこと • ボタンの動作を設定 何度かボタンを押す

  4. 動作の設定 Android では, JAVAという言語を使って動作設定する JAVA を説明する前に・・・ 実際にどういうものか見てみよう!!

  5. 画面を設計 (XML) 1/3 前回も編集した この場所にあるXMLを編集する

  6. 画面を設計 (XML) 2/3 1<?xmlversion="1.0"encoding="utf-8"?> 2<LinearLayoutxmlns:android="http://... 3android:orientation="vertical" 4android:layout_width="fill_parent" 5android:layout_height="fill_parent" 6> 7<Button 8android:id="@+id/button" 9android:layout_width="wrap_content" 10android:layout_height="wrap_content" 11android:text="Button" 12/> 13<TextView 14android:id="@+id/text" 15android:layout_width="fill_parent" 16android:layout_height="wrap_content" 17/> 18</LinearLayout> 前回までは無かったもの どのボタンか, どのテキストビューか, 指定するために 必要な記述

  7. 画面を設計 (XML) 3/3 このボタンに 「button」という IDをつける 1<?xmlversion="1.0"encoding="utf-8"?> 2<LinearLayoutxmlns:android="http://... 3android:orientation="vertical" 4android:layout_width="fill_parent" 5android:layout_height="fill_parent" 6> 7<Button 8android:id="@+id/button" 9android:layout_width="wrap_content" 10android:layout_height="wrap_content" 11android:text="Button" 12/> 13<TextView 14android:id="@+id/text" 15android:layout_width="fill_parent" 16android:layout_height="wrap_content" 17/> 18</LinearLayout> ID:button ID:text テキストビュー このテキストビューに 「text」という IDをつける

  8. 動作を設定 (JAVA) 1/5 この場所にあるJAVAを編集する

  9. 動作を設定 (JAVA) 2/5 1public class Hello extends Activity { 2TextView tv; 3Button button; 4 5public void onCreate(Bundle savedInstanceState){ 6super.onCreate(savedInstanceState); 7setContentView(R.layout.main); 8tv=(TextView)findViewById(R.id.text); 9 10button = (Button)findViewById(R.id.button); 11button.setOnClickListener(new View.OnClickListener(){ 12public void onClick(View arg0){ 13tv.append("Hello World!\n"); 14} 15}); 16} 17} これが完成形

  10. 動作を設定 (JAVA) 3/5 tv というものを用意する ~ 2TextView tv; ~ 8tv=(TextView)findViewById(R.id.text); ID:button • IDを「text」としたテキストビューをJAVA で扱えるようになる • テキストビューに対して動作を設定するための準備 ID:text テキストビュー

  11. button というものを用意する 動作を設定 (JAVA) 4/5 ~ 3Button button; ~ 10button=(Button)findViewById(R.id.button); ID:button • IDを「button」としたボタンをJAVA で扱えるようになる • ボタンに対して動作を設定するための準備 ID:text テキストビュー

  12. 動作を設定 (JAVA) 5/5 11button.setOnClickListener(new View.OnClickListener(){ 12public void onClick(View arg0){ 13tv.append("Hello World!\n"); 14} 15}); 16} • button に対して動作の設定をする • 13行目で動作を記述している • tv に「HelloWorld!」という文字列を追加するという動作 • \n は改行することを表している

  13. 動作を設定 (JAVA) 6/6 • このマークが出たら,そのマークをクリック • 一番上の項目を選択

  14. 他の動作 • テキストの色を変える • テキストの大きさを変える

  15. テキストの色を変える 1/2 1public class Hello extends Activity{ 2TextView tv; 3Button button; 4 5public void onCreate(Bundle savedInstanceState){ 6super.onCreate(savedInstanceState); 7setContentView(R.layout.main); 8tv = (TextView)findViewById(R.id.text); 9tv.setText("Hello World!"); 10 11button = (Button)findViewById(R.id.button); 12button.setOnClickListener(newV iew.OnClickListener(){ 13public void onClick(Viewa rg0){ 14tv.setTextColor(Color.RED); 15} 16}); 17} 18} 2か所の変更点 これが完成形

  16. テキストの色を変える 2/2 9tv.setText("Hello World!"); あらかじめテキストビューに「Hello World!」と表示させておく • tv.setTextColor(Color.RED); Color.色 で,テキストを指定した色に変更する クリック

  17. テキストの大きさを変える 1/2 1public class Hello extends Activity{ 2TextView tv; 3Button button; 4 5public void onCreate(Bundle savedInstanceState){ 6super.onCreate(savedInstanceState); 7setContentView(R.layout.main); 8tv = (TextView)findViewById(R.id.text); 9tv.setText("Hello World!"); 10 11button = (Button)findViewById(R.id.button); 12button.setOnClickListener(newV iew.OnClickListener(){ 13public void onClick(Viewa rg0){ 14 tv.setTextSize(50); 15} 16}); 17} 18} 1か所の変更点 これが完成形

  18. テキストの大きさを変える 2/2 • tv.setTextSize(50); ()内の数字で指定した大きさに変更する クリック

  19. 課題 • 前回作った画面に動作を設定してみよう

More Related