-1

我的活动中有一个复选框。

当用户按下保存按钮并离开复选框uncheckedinstead of '0',它将被保存为NO.

但是当用户ticked the checkbox保存它时instead of '1',它会被保存为YES.

4

2 回答 2

1
CheckBox c;
String SaveString="No";
//Initialize CheckBox
c.setOnCheckedChangeListener(new OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton arg0, boolean checked) {
        // TODO Auto-generated method stub
        if(checked)
        {
            SaveString="Yes";
        }
        else
        {
            SaveString="No";
        }
    }
});

现在,

 SaveDatabase(SaveString);
于 2013-07-03T05:15:58.743 回答
1
  btnSave.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub  

    CheckBox c = (CheckBox) findViewById(R.id.checkBox1);


    if (c.isChecked())
     { // save to String Variable for yes, strCheckBox="yes";
     }
    else
    {  // save to String Variable for No, strCheckBox="no";
    }

   //Code for Save to database

}
    });             
于 2013-07-03T05:26:00.400 回答