gpt4 book ai didi

android - 将 CheckBox 值插入 SQLite Android

转载 作者:太空狗 更新时间:2023-10-29 13:36:16 24 4
gpt4 key购买 nike

我有这个数据库查询:

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());


但是不行...
我想在选中或未选中时将选中的值存储到数据库中。
我该怎么做?

谢谢。

最佳答案

第一期:

您正在为选中的每个复选框上的 checked 字符串变量赋值,因此无论您选择了 2 个复选框还是单个复选框,最后您都将只有 1 个字符串值,相反您应该创建 String [] 选中复选框的数组。

第二期:

在单击按钮时,您正在尝试调用数据库的 checkBox 方法,在这里您再次只是获取 CheckBox 标题的值,因此这里是否选中复选框并不重要未选中。

关于android - 将 CheckBox 值插入 SQLite Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com