0

So here is the following code here is the XML for the checkboxes

 <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Remember me"
            android:id="@+id/rememberMe"
            android:checked="false"
            android:hint="Save my login details"
            android:onClick="CheckboxIsTicked"
            />


        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="I agree on the terms &amp; conditions"
            android:id="@+id/tandc"
            android:checked="false"
            android:onClick="CheckboxIsTicked"
            />

and here is my function to test if it has been clicked by changing a textbox

   public void CheckboxIsTicked(View v) {

            boolean checked = ((CheckBox) v).isChecked();

                switch (v.getId()) {
                    case R.id.rememberMe:
                        if (checked) {
                            //((EditText) findViewById(R.id.et_username)).setText("test");
                        } else {
                            break;
                        }

                    case R.id.tandc:
                        if (checked) {
                            //((EditText) findViewById(R.id.et_username)).setText("test");
                        } else {
                            break;
                        }
                }
            }

However my program crashes as soon as I click either checkbox

Any suggestions on what I am doing wrong?

1 Answers1

0

This is not crashing, you may forget to put the edittext, put the entire code to fix this issue and the code should be like

public void CheckboxIsTicked(View v) {
    boolean checked = ((CheckBox) v).isChecked();
    switch (v.getId()) {
        case R.id.rememberMe:
            if (checked) {
                // ((EditText) findViewById(R.id.etEmail)).setText("test");
            } else {

            }
            break;
        case R.id.tandc:
            if (checked) {
                // ((EditText) findViewById(R.id.etEmail)).setText("test");
            } else {

            }
            break;
    }
}