ボタン
単純な、テキスト付きボタンは Button、画像を付けたボタンは ImageButton をつかうが、Button に drawableLeft 属性をつけてテキストの左側に画像をつけることもできる。
配置
<Button
android:id="@+id/btConnection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HOGE" />
クリックへの処理をつける
属性で指定、OnClickListener で指定、の方法がある。
属性での指定
一番簡単?(単純)につけるなら、レイアウトの Button に onClick 属性をつける。
android:onClick="sendMessage"
そして、Activity に処理を記述しておく
public void sendMessage(View view) {...}
OnClickListener での指定
View.OnClickListener オブジェクトを生成して、Button オブジェクトにリスナーを割り付ける。
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {...}
});
チェックボックス
レイアウトへの表示
<Checkbox
android:id="@+id/cbTestified"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CHECKBOX TEXT" />
値の読み取り
最終更新:2017年05月02日 21:52