Android Studio Questions

Asked 2 years ago, Updated 2 years ago, 21 views

Regardless of which of the two check boxes is checked, I would like to change calendarview to visible. The default status for xml is invisible. The error keeps appearing on the second override, so I would appreciate it if you could tell me what the problem is and which part I should change. It's very difficult because it's my first time dealing with Java and I know it by looking at the example.

package com.example.ansimyoyang_ipsoza;

import android.os.Bundle; import android.view.View; import android.widget.CalendarView; import android.widget.CheckBox; import android.widget.CompoundButton;

import androidx.appcompat.app.AppCompatActivity;

public class meetingbook extends AppCompatActivity {

CheckBox checkbox_facebook;
CheckBox checkbox_nofacebook;
CalendarView calendarView;


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

    checkbox_facebook = (CheckBox)findViewById(R.id.checkbox_facebook);
    checkbox_nofacebook = (CheckBox)findViewById(R.id.checkbox_nofacebook);
    calendarView=(CalendarView)findViewById(R.id.calendarView);
    checkbox_facebook.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) this);
    checkbox_nofacebook.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) this);
}

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    if(checkbox_facebook.isChecked()) calendarView.setVisibility(View.VISIBLE);;
    if(checkbox_nofacebook.isChecked()) calendarView.setVisibility(View.VISIBLE);
}

}

android

2022-09-20 19:57

1 Answers

The annotation @Override means that this method overrides a predefined method for an inherited parent or implemented interface.

Currently, the meetingbook class of the code inherits AppCompatActivity. This parent class does not have a method defined called onCheckedChanged.

//public class meetingbook extends AppCompatActivity 

public class meetingbook extends AppCompatActivity implements OnCheckedChangeListener

Please change it like this.


2022-09-20 19:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.