カテゴリー:
Activityクラス
閲覧数:467 配信日:2013-04-19 10:31
実装例1
「ビューに対して割り当てられたリソースID」とは、下記の場合「main.xml」に記載された「Button1」を指す
▼/src/パッケージ名/MainActivity.java
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //レイアウト用XMLファイルを設定 // ダイアラーボタンを押下したとき Button dialButton = (Button) findViewById(R.id.Button1); |
・レイアウト用XMLファイル
▼/res/layout/main.xml
<Button android:id= "@+id/Button1" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:text= "ダイアラー起動" /> |
実装例2
▼/src/com/fc2/blog98/andromaker/housekeepingbook/HousekeepingBook.java
setContentView(R.layout.main); /* 変数の設定 */ int[] calendar=intentCalendar(); /* コンポーネントの設定 */ monthButton = (Button)this.findViewById(R.id.monthButton); dateButton = (Button)this.findViewById(R.id.dateButton); addButton = (Button)this.findViewById(R.id.addButton); deleteButton = (Button)this.findViewById(R.id.deleteButton); sumText=(TextView)this.findViewById(R.id.sumText); |
▼/res/layout/main.xml
<Button android:id= "@+id/monthButton" android:layout_width= "120px" android:layout_height= "wrap_content" android:text= "@string/btn_label1" /> <Button android:id= "@+id/dateButton" android:layout_width= "200px" android:layout_height= "wrap_content" android:layout_marginLeft= "20.0px" /> <Button android:id= "@+id/addButton" android:layout_width= "80px" android:layout_height= "wrap_content" android:background = "@android:drawable/ic_menu_add" android:layout_marginLeft= "20.0px" /> |
<Button android:id= "@+id/deleteButton" android:layout_width= "200px" android:layout_height= "wrap_content" android:text= "一括削除" /> <TextView android:id= "@+id/sumText" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginLeft= "10.0px" /> |