안드로이드 스튜디오 질문
조회수 485회
checkbox 두 개중 무엇이 체크되건 간에 calendarview를 visible로 바꾸고 싶습니다. xml에서의 기본 상태는 invisible입니다. 계속 두 번째 override에서 오류가 뜨는데 무엇이 문제인지, 어느 부분을 바꾸면 좋을 지 알려주시면 감사하겠습니다. 자바를 처음 다루어보고 예제를 보고 알음알음 짜는지라 많이 어렵네요...
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);
}
}
1 답변
-
@Override 라는 어노테이션은 이 메서드가 상속된 부모 혹은 구현된 인터페이스에 미리 정의된 메서드를 재정의 한다는 뜻입니다.
현재 코드의 meetingbook 클래스는 AppCompatActivity 를 상속받고 있는데요. 해당 부모 클래스에는 onCheckedChanged 라는 메서드가 정의되어있지 않습니다.
//public class meetingbook extends AppCompatActivity public class meetingbook extends AppCompatActivity implements OnCheckedChangeListener
이렇게 한번 바꿔보시기 바랍니다.
댓글 입력