Android:(简单)缺少导入或。。。?

Android:(简单)缺少导入或。。。?,android,android-widget,listener,actionlistener,Android,Android Widget,Listener,Actionlistener,我正在跟随一本书学习Android,我得到了一个错误,这是我的代码 我正在使用上面的图像,以便您也可以看到错误(compoundbutton) 是我打错了什么,还是这本书没有写一些需要的东西 谢谢 编辑完整代码: package newbook.appress; import android.app.Activity; import android.os.Bundle; import android.widget.CheckBox; import android.widget.Compound

我正在跟随一本书学习Android,我得到了一个错误,这是我的代码

我正在使用上面的图像,以便您也可以看到错误(compoundbutton)

是我打错了什么,还是这本书没有写一些需要的东西

谢谢

编辑完整代码:

package newbook.appress;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;

public class CheckBoxDemo extends Activity 
implements CompoundButton.OnCheckChangedListener{

    CheckBox cb;

     @Override 
      public void onCreate(Bundle icicle) { 
        super.onCreate(icicle); 
        setContentView(R.layout.main); 

        cb=(CheckBox)findViewById(R.id.chkBox1);
        cb.setOnCheckedChangeListener(this);
     }


     public void onCheckedChanged(CompoundButton buttonView, 
             boolean isChecked) { 
        if (isChecked) { 
        cb.setText("This checkbox is: checked"); 
        } 
        else { 
        cb.setText("This checkbox is: unchecked"); 
        } 
        }

}

这是正确的。你需要导入所有东西。您缺少:

    import android.widget.CompoundButton
您可以键入:

CtrlShift+O到O在Eclipse中自动组织导入

您还需要将第二个错误更改为:

cb.setOnCheckedChangeListener(this);

我假设这是eclipse,当您将鼠标悬停在红色部分上时,错误会显示什么?是的,“compoundButton无法解析为类型”确定,这样做了,它将compoundButton添加到导入列表中,但仍然存在错误,并显示“compoundButton.OnCheckChangedListener无法解析为类型”Ryan,正确的类名是CompoundButton.OnCheckedChangeListener,而不是CompoundButton.OnCheckChangeListener:)