jeudi 12 mai 2016

Android Studio - Trying to program an event driven Checkbox click

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?

Aucun commentaire:

Enregistrer un commentaire