B main xml xml version1 0 encodingutf8 Linear


B. 「main. xml」の内容 (配置後、確認) <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" android: layout_width="fill_parent" android: layout_height="fill_parent" android: orientation="vertical" > <Text. View android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/hello" /> <Toggle. Button android: id="@+id/toggle. Button 1" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="Toggle. Button" /> </Linear. Layout>

C. 「R. java」の内容 (配置後、実行すると生成される) package jp. eclipse; public final class R { public static final class attr { } public static final class drawable { public static final int ic_launcher=0 x 7 f 020000; } public static final class id { public static final int toggle. Button 1=0 x 7 f 050000; } public static final class layout { public static final int main=0 x 7 f 030000; } public static final class string { public static final int app_name=0 x 7 f 040001; public static final int hello=0 x 7 f 040000; } }

D. ソースプログラム(その 1) package jp. eclipse; import import android. app. Activity; android. os. Bundle; android. view. View; android. widget. *; android. widget. Compound. Button. On. Checked. Change. Listener; public class Toggle. Button. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); final Activity activity=this; (次ページに続く)

ソースプログラム(その2) Toggle. Button toggle 1 = (Toggle. Button)this. find. View. By. Id(R. id. toggle. Button 1); toggle 1. set. On. Checked. Change. Listener (new On. Checked. Change. Listener(){ @Override public void on. Checked. Changed (Compound. Button button. View, boolean is. Checked){ Toast toast=Toast. make. Text(activity, "指定:" +is. Checked, Toast. LENGTH_LONG); toast. show(); } }



B. 「main. xml」の内容 (配置後、確認) <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" android: layout_width="fill_parent" android: layout_height="fill_parent" android: orientation="vertical" > <Text. View android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/hello" /> <Check. Box android: id="@+id/check. Box 1" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="これを選ぶか?" /> </Linear. Layout>

C. 「R. java」の内容 (配置後、実行すると生成される) package jp. eclipse; public final class R { public static final class attr { } public static final class drawable { public static final int ic_launcher=0 x 7 f 020000; } public static final class id { public static final int check. Box 1=0 x 7 f 050000; } public static final class layout { public static final int main=0 x 7 f 030000; } public static final class string { public static final int app_name=0 x 7 f 040001; public static final int hello=0 x 7 f 040000; } }

D. ソースプログラム(その 1) package jp. eclipse; import android. app. Activity; import android. os. Bundle; import android. widget. *; import android. widget. Compound. Button. On. Checked. Change. Listener; public class Check. Box. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); final Activity activity = this;

ソースプログラム(その 2) Check. Box check 1 = (Check. Box) this. find. View. By. Id (R. id. check. Box 1); check 1. set. On. Checked. Change. Listener (new On. Checked. Change. Listener(){ @Override public void on. Checked. Changed (Compound. Button button. View, boolean is. Checked){ Toast toast = Toast. make. Text(activity, "選択: "+is. Checked, Toast. LENGTH_LONG); toast. show(); } }



B. 「main. xml」の内容(その1) (配置後、確認) <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" android: layout_width="fill_parent" android: layout_height="fill_parent" android: orientation="vertical" > <Text. View android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/hello" />

「main. xml」の内容(その2) <Radio. Button android: id="@+id/radio 0" android: layout_width="wrap_content" android: layout_height="wrap_content" android: checked="true" android: text="情報 学科" /> <Radio. Button android: id="@+id/radio 1" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="電気電子 学科" /> <Radio. Button android: id="@+id/radio 2" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="システム 学科" /> </Radio. Group> </Linear. Layout>

C. 「R. java」の内容(その1) (配置後、実行すると生成される) package jp. eclipse; public final class R { public static final class attr { } public static final class drawable { public static final int ic_launcher=0 x 7 f 020000; } public static final class id { public static final int radio 0=0 x 7 f 050001; public static final int radio 1=0 x 7 f 050002; public static final int radio 2=0 x 7 f 050003; public static final int radio. Group 1=0 x 7 f 050000; }

「R. java」の内容(その2) public static final class layout { public static final int main=0 x 7 f 030000; } public static final class string { public static final int app_name=0 x 7 f 040001; public static final int hello=0 x 7 f 040000; } }

D. ソースプログラム(その 1) package jp. eclipse; import android. app. Activity; import android. os. Bundle; import android. widget. *; import android. widget. Radio. Group. On. Checked. Change. Listener; public class Radio. Button. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); final Activity activity = this;

D. ソースプログラム(その 1) Radio. Group group 1 = (Radio. Group)this. find. View. By. Id(R. id. radio. Group 1); group 1. set. On. Checked. Change. Listener (new On. Checked. Change. Listener(){ @Override public void on. Checked. Changed (Radio. Group group, int checked. ID) { Radio. Button btn =(Radio. Button)find. View. By. Id(checked. ID); Toast toast = Toast. make. Text(activity, "選択: "+btn. get. Text(), Toast. LENGTH_LONG); toast. show(); } }











B. 「main. xml」の内容 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" android: layout_width="fill_parent" android: layout_height="fill_parent" android: orientation="vertical" > <Text. View android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/hello" /> <Spinner android: id="@+id/spinner 1" android: layout_width="match_parent" android: layout_height="wrap_content" android: entries="@array/list 1"/> </Linear. Layout>

C. 「string. xml」の内容 <? xml version="1. 0" encoding="utf-8"? > <resources> <string name="hello">Hello World, Spinner. Activity!</string> <string name="app_name">Spinner</string> <string-array name="list 1"> <item >乗用車</item> <item >トラック</item> <item >オープンカー</item> </string-array> </resources>

package jp. exclipse; D. 「R. java」の内容 public final class R { public static final class array { public static final int list 1=0 x 7 f 050000; } public static final class attr { } public static final class drawable { public static final int ic_launcher=0 x 7 f 020000; } public static final class id { public static final int spinner 1=0 x 7 f 060000; } public static final class layout { public static final int main=0 x 7 f 030000; } public static final class string { public static final int app_name=0 x 7 f 040001; public static final int hello=0 x 7 f 040000; } }

E. 現時点でのソースプログラム package jp. exclipse; import android. app. Activity; import android. os. Bundle; public class Spinner. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); } }

F. ソースプログラム(その 1) イベントとしてOn. Click ではなく、On. Item. Selected. Listenerを使用 package jp. exclipse; import android. app. Activity; import android. os. Bundle; import android. view. View; import android. widget. Adapter. View. On. Item. Selected. Listener; import android. widget. *; public class Spinner. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); final Activity activity = this; Spinner spinner =(Spinner)this. find. View. By. Id(R. id. spinner 1); spinner. set. On. Item. Selected. Listener (new On. Item. Selected. Listener(){

ソースプログラム(その2) @Override public void on. Item. Selected(Adapter. View<? > parent, View view, int position, long id) { Spinner spinner=(Spinner)parent; String str=(String)spinner. get. Selected. Item(); Toast toast =Toast. make. Text(activity, "選択された項目:"+str, Toast. LENGTH_LONG); toast. show(); } @Override public void on. Nothing. Selected(Adapter. View<? > parent) { Toast toast =Toast. make. Text(activity, “未選択!!”, Toast. LENGTH_LONG); toast. show(); } }






⑦仮実行して「R. java」を確認 ⑦実行しても「on. Action」がないのでエラーとなるが構わない。 「R. java」に「R. id」が生成されていることを確認する。 package jp. eclipse; public final class R { public static final class attr { } public static final class drawable { public static final int ic_launcher=0 x 7 f 020000; public static final int sample 1=0 x 7 f 020001; } public static final class id { public static final int button 1=0 x 7 f 050000; public static final int image. View 1=0 x 7 f 050001; } public static final class layout { public static final int main=0 x 7 f 030000; } public static final class string { public static final int app_name=0 x 7 f 040001; public static final int hello=0 x 7 f 040000; } }
![[main. xml] B. 「main. xml」の内容 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: [main. xml] B. 「main. xml」の内容 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns:](http://slidetodoc.com/presentation_image_h2/25065ab589541b60148569ff0b74b16f/image-42.jpg)
[main. xml] B. 「main. xml」の内容 <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" android: layout_width="fill_parent" android: layout_height="fill_parent" android: orientation="vertical" > <Button android: id="@+id/button 1" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="画像表示" android: on. Click="do. Action"/> <Image. View android: id="@+id/image. View 1" android: layout_width="wrap_content" android: layout_height="wrap_content" android: src="@drawable/ic_launcher" /> </Linear. Layout>

package jp. eclipse; C. ソースプログラム import android. app. Activity; import android. os. Bundle; import android. view. View; import android. widget. Image. View; public class Image. View. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); } public void do. Action(View view){ Image. View image. V =(Image. View)find. View. By. Id(R. id. image. View 1); image. V. set. Image. Resource(R. drawable. sample 1); } }

- Slides: 44