如何使用复选框以检查状态? [英] How to check condition using checkbox?

查看:147
本文介绍了如何使用复选框以检查状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JSON将值发送到服务器,当我选择复选框,我想送Y,,在我的JSON有效= Y为用户激活和关闭的状态是什么,我想是,,以下是$ C $Ç我的尝试,但它不工作,它总是显示激活= N

  proactives =(复选框)findViewById(R.id.edt_proactive);
     如果(proactives.isChecked()==真)
      {
          proactives.setTag(Y);
      }
      如果(proactives.isChecked()==假)
      {
          proactives.setTag(N);
      }
 

解决方案

试试这个

  proactives.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){
        @覆盖
        公共无效onCheckedChanged(CompoundButton compoundButton,布尔B){
            如果(B)的
            {
                proactives.setTag(Y);
            }
            如果(proactives.isChecked()==假)
            {
                proactives.setTag(N);
            }
        }
    });
 

  proactives.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){
            @覆盖
            公共无效onCheckedChanged(CompoundButton compoundButton,布尔B){
              proactives.setTag(BY:N);
            }
        });
 

I am trying to send value to server using json,what I am trying is when I select checkbox I want to send "Y",,in my json active=Y is status of user activation and deactivation,,following is code what i tried,but its not working,it always shows active=N

 proactives=(CheckBox)findViewById(R.id.edt_proactive);
     if(proactives.isChecked()==true)
      {
          proactives.setTag("Y");
      }
      if(proactives.isChecked()==false)
      {
          proactives.setTag("N");
      }

解决方案

try this

proactives.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if(b)
            {
                proactives.setTag("Y");
            }
            if(proactives.isChecked()==false)
            {
                proactives.setTag("N");
            }
        }
    });

OR

proactives.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
              proactives.setTag(b? "Y" : "N"); 
            }
        });

这篇关于如何使用复选框以检查状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆