私はこのデータベースクエリを持っています:
public void checkBox(String fasil1,String fasil2,String fasil3,String fasil4,String fasil5,String fasil6,String fasil7,
String fasil8,String fasil9,String fasil10,String fasil11,String fasil12,String fasil13,String fasil14){
ContentValues cv = new ContentValues();
cv.put("fasil1", fasil1);
cv.put("fasil2", fasil2);
cv.put("fasil3", fasil3);
cv.put("fasil4", fasil4);
cv.put("fasil5", fasil5);
cv.put("fasil6", fasil6);
cv.put("fasil7", fasil7);
cv.put("fasil8", fasil8);
cv.put("fasil9", fasil9);
cv.put("fasil10", fasil10);
cv.put("fasil11", fasil11);
cv.put("fasil12", fasil12);
cv.put("fasil13", fasil13);
cv.put("fasil14", fasil14);
getWritableDatabase().insert("fasil", "name", cv);
}
これは私のCheckBoxコードです:
fasil1 = (CheckBox)findViewById(R.id.rs);
fasil1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Rumah Sakit";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil2 = (CheckBox)findViewById(R.id.skul);
fasil2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Sekolah";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil3 = (CheckBox)findViewById(R.id.kampus);
fasil3.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Kampus";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil4 = (CheckBox)findViewById(R.id.officeBuild);
fasil4.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Office Building";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil5 = (CheckBox)findViewById(R.id.apartemen);
fasil5.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Apartemen";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil6 = (CheckBox)findViewById(R.id.hotel);
fasil6.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Hotel";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil7 = (CheckBox)findViewById(R.id.bank);
fasil7.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Bank";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil8 = (CheckBox)findViewById(R.id.spbu);
fasil8.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "SPBU";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil9 = (CheckBox)findViewById(R.id.pasar);
fasil9.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Pasar";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil10 = (CheckBox)findViewById(R.id.wisata);
fasil10.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Jalur Wisata / Tempat Wisata";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil11 = (CheckBox)findViewById(R.id.terminal);
fasil11.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Stasiun / Terminal";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil12 = (CheckBox)findViewById(R.id.bandara);
fasil12.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Bandara / Airport";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil13 = (CheckBox)findViewById(R.id.mol);
fasil13.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Mal / Shoping Center";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
fasil14 = (CheckBox)findViewById(R.id.hiburan);
fasil14.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
checked = "Entertainment";
Toast.makeText(CobaCombo.this, checked, Toast.LENGTH_SHORT).show();
}else{
checked = "-";
}
}
});
次に、ボタンがクリックされたときに値を保存するコードがあります。
helper.checkBox(fasil1.getText().toString(), fasil2.getText().toString(), fasil3.getText().toString(),
fasil4.getText().toString(), fasil5.getText().toString(), fasil6.getText().toString(),
fasil7.getText().toString(), fasil8.getText().toString(), fasil9.getText().toString(),
fasil10.getText().toString(), fasil11.getText().toString(), fasil12.getText().toString(),
fasil13.getText().toString(), fasil14.getText().toString());
しかし、それはうまくいきません...チェックされているかチェックされていないときに、データベースにチェックインされた値
を保存したいです。どうすればそれができますか?
ありがとうございました。