gpt4 book ai didi

java - onCheckedChangeListener 不适用于 Android Studio

转载 作者:行者123 更新时间:2023-11-29 07:45:05 24 4
gpt4 key购买 nike

我一直在关注 NerdRanch Android 教程 [第 8 章,Wiring Widgets] 并遇到了这个麻烦的错误。这是我收到的错误:

Class 'Anonymous class derived from OnCheckedChangeListener' must either be declared abstract or implement abstract method 'onCheckedChange(CompoundButton, boolean)' in 'OnCheckedChangeListener'

这是我的 CrimeFragment.java 的代码

package com.example.justin.criminalintent;

// imports...

import static android.widget.CompoundButton.OnCheckedChangeListener;

public class CrimeFragment extends Fragment {
private Crime mCrime;
private EditText mTitleField;
private Button mDateButton;
private CheckBox mSolvedCheckBox;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCrime = new Crime();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_crime, parent, false);

mTitleField = (EditText)v.findViewById(R.id.crime_title);
mTitleField.addTextChangedListener(new TextWatcher() {
public void onTextChanged(
CharSequence c, int start, int before, int count) {
mCrime.setTitle(c.toString());
}

public void beforeTextChanged(
CharSequence c, int start, int count, int after) {
//This space intentionally left blank
}

public void afterTextChanged(Editable c) {
// This one too
}
});

//Get a reference to the new button, set its text as date of the crime
mDateButton = (Button)v.findViewById(R.id.crime_date);
mDateButton.setText(mCrime.getDate().toString());
mDateButton.setEnabled(false);

//Get a reference to the checkbox, and set a listener that will update
// the mSolved field of the CRIME
mSolvedCheckBox = (CheckBox)v.findViewById(R.id.crime_solved);
mSolvedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

public void onCheckedChange(CompoundButton buttonView, boolean isChecked) {
//Set the crime's solved property
mCrime.setSolved(isChecked);
}
});

return v;
}
}

这是来自 Gradle 构建的日志:

C:\Users\Justin\Desktop\CriminalIntent\app\src\main\java\com\example\justin\criminalintent\CrimeFragment.java
Error:(65, 82) error: <anonymous com.example.justin.criminalintent.CrimeFragment$2> is not abstract and does not override abstract method onCheckedChanged(CompoundButton,boolean) in OnCheckedChangeListener
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED

关于如何修复此错误的任何想法?

最佳答案

换行

 public void onCheckedChange(CompoundButton buttonView, boolean isChecked) {

 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

关于java - onCheckedChangeListener 不适用于 Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26565995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com