开发者

Android: (simple) missing import or...?

I am following a book to learn Android and am getting an error, this is my code

Android: (simple) missing import or...?

I am using an image above so you can see the error as well (compoundbutton).

Did I type something wrong or did the book not write some of the imports needed?

Thanks!

EDITED full code:

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开发者_JAVA技巧 is: unchecked"); 
        } 
        }

}


That is correct. you need to import everything. You are missing:

    import android.widget.CompoundButton

You can type:

CtrlShift+O to O rganize your imports automatically in Eclipse.

You'll also want to change the second error to:

cb.setOnCheckedChangeListener(this);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜