lundi 18 mars 2019

App crashes if check box isn't clicked before button is pressed

My app works in terms of navigation whilst the check box is ticked, but of course in the use of the app the check box will not always be checked and accounts for something else instead. My code:

      checkBox.setOnClickListener(this);
        // called when check box is clicked

    }

    @Override
    public void onClick(View v) {
        //method called
        if (checkBox.isChecked())
        {
            userPin.setVisibility(View.VISIBLE);
            //when checkbox is check, userPin becomes visible
        }
        else
        {
            userPin.setVisibility(View.INVISIBLE);
            //otherwise userPin is invisible
        }

        GoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
           public void onClick(View v) {
               ChangeActivityStudent();
            }
        });
   }
    private void ChangeActivityStudent(){
       Intent intent = new Intent(MainActivity.this, StudentActivity.class);
       startActivity(intent);
    }


    }

I need to be able for the the Go btn to work regardless of the state of the check box

Thanks in advanced




Aucun commentaire:

Enregistrer un commentaire