java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.Button
↳ android.widget.CompoundButton
↳ android.widget.CheckBoxを使用しますというわけで、CheckBox をいじってみた
サンプルプログラム
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
public class CheckBoxTest extends Activity {
CheckBox checkBox;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkboxtest);
checkBox = (CheckBox) findViewById(R.id.CheckBox01);
// CheckBox のチェック状態の設定
checkBox.setChecked(true);
// CheckBox がクリックされた時に呼び出されるコールバックを登録
checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// クリックされた CheckBox を取得
CheckBox checkBox = (CheckBox) v;
// CheckBox のチェック状態を取得
boolean checked = checkBox.isChecked();
}
});
}
}
XMLリソース
<CheckBox android:id="@+id/CheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CheckBox"> </CheckBox>
プログラムを実行すると...
こんな感じ!

0 件のコメント:
コメントを投稿