Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Nothing happens when CheckBox is checked

Nothing happens when CheckBox is checked

Scheduled Pinned Locked Moved Java
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pavlex4
    wrote on last edited by
    #1

    I created program where when user checks checkbox edit text is enabled, but when I check any of checkboxes nothing happens!!!

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        editText2 = (EditText) findViewById(R.id.editText\_symbols);
        editText3 = (EditText) findViewById(R.id.editText\_numbers);
        editText4 = (EditText) findViewById(R.id.editText\_lowercase);
        editText5 = (EditText) findViewById(R.id.editText\_uppercase);
    
        editText2.setEnabled(false);
        editText3.setEnabled(false);
        editText4.setEnabled(false);
        editText5.setEnabled(false);
    }
    
    public void checkCheckBox(View view)
    {
        boolean checked = (((CheckBox)view).isChecked());
        switch (view.getId())
        {
            case R.id.checkBox\_uppercase:
                if(checked)
                    editText2.setEnabled(true);
                else
                    editText2.setEnabled(false);
                break;
    
            case R.id.checkBox\_lowercase:
                if(checked)
                    editText3.setEnabled(true);
                else
                    editText3.setEnabled(false);
                break;
    
            case R.id.checkBox\_numbers:
                if(checked)
                    editText4.setEnabled(true);
                else
                    editText4.setEnabled(false);
                break;
    
            case R.id.checkBox\_symbols:
                if(checked)
                    editText5.setEnabled(true);
                else
                    editText5.setEnabled(false);
                break;
        }
    
    }
    
    L M 2 Replies Last reply
    0
    • P Pavlex4

      I created program where when user checks checkbox edit text is enabled, but when I check any of checkboxes nothing happens!!!

      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

          editText2 = (EditText) findViewById(R.id.editText\_symbols);
          editText3 = (EditText) findViewById(R.id.editText\_numbers);
          editText4 = (EditText) findViewById(R.id.editText\_lowercase);
          editText5 = (EditText) findViewById(R.id.editText\_uppercase);
      
          editText2.setEnabled(false);
          editText3.setEnabled(false);
          editText4.setEnabled(false);
          editText5.setEnabled(false);
      }
      
      public void checkCheckBox(View view)
      {
          boolean checked = (((CheckBox)view).isChecked());
          switch (view.getId())
          {
              case R.id.checkBox\_uppercase:
                  if(checked)
                      editText2.setEnabled(true);
                  else
                      editText2.setEnabled(false);
                  break;
      
              case R.id.checkBox\_lowercase:
                  if(checked)
                      editText3.setEnabled(true);
                  else
                      editText3.setEnabled(false);
                  break;
      
              case R.id.checkBox\_numbers:
                  if(checked)
                      editText4.setEnabled(true);
                  else
                      editText4.setEnabled(false);
                  break;
      
              case R.id.checkBox\_symbols:
                  if(checked)
                      editText5.setEnabled(true);
                  else
                      editText5.setEnabled(false);
                  break;
          }
      
      }
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See Android Tutorials[^].

      1 Reply Last reply
      0
      • P Pavlex4

        I created program where when user checks checkbox edit text is enabled, but when I check any of checkboxes nothing happens!!!

        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

            editText2 = (EditText) findViewById(R.id.editText\_symbols);
            editText3 = (EditText) findViewById(R.id.editText\_numbers);
            editText4 = (EditText) findViewById(R.id.editText\_lowercase);
            editText5 = (EditText) findViewById(R.id.editText\_uppercase);
        
            editText2.setEnabled(false);
            editText3.setEnabled(false);
            editText4.setEnabled(false);
            editText5.setEnabled(false);
        }
        
        public void checkCheckBox(View view)
        {
            boolean checked = (((CheckBox)view).isChecked());
            switch (view.getId())
            {
                case R.id.checkBox\_uppercase:
                    if(checked)
                        editText2.setEnabled(true);
                    else
                        editText2.setEnabled(false);
                    break;
        
                case R.id.checkBox\_lowercase:
                    if(checked)
                        editText3.setEnabled(true);
                    else
                        editText3.setEnabled(false);
                    break;
        
                case R.id.checkBox\_numbers:
                    if(checked)
                        editText4.setEnabled(true);
                    else
                        editText4.setEnabled(false);
                    break;
        
                case R.id.checkBox\_symbols:
                    if(checked)
                        editText5.setEnabled(true);
                    else
                        editText5.setEnabled(false);
                    break;
            }
        
        }
        
        M Offline
        M Offline
        Mirwise Khan
        wrote on last edited by
        #3

        Try this

        ((CheckBox)view).setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
                switch (view.getId())
                {
                case R.id.checkBox\_uppercase:
                    if(checked)
                        editText2.setEnabled(true);
                    else
                        editText2.setEnabled(false);
                    break;
        
                case R.id.checkBox\_lowercase:
                    if(checked)
                        editText3.setEnabled(true);
                    else
                        editText3.setEnabled(false);
                    break;
        
                case R.id.checkBox\_numbers:
                    if(checked)
                        editText4.setEnabled(true);
                    else
                        editText4.setEnabled(false);
                    break;
        
                case R.id.checkBox\_symbols:
                    if(checked)
                        editText5.setEnabled(true);
                    else
                        editText5.setEnabled(false);
                    break;
                }
            }
        });
        

        Late but hope this helps!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups