Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:30:51+00:00 2026-06-16T21:30:51+00:00

public class CheckBoxDemo extends Activity implements CompoundButton.OnCheckedChangeListener { CheckBox cb; @Override public void onCreate(Bundle

  • 0
public class CheckBoxDemo extends Activity implements
    CompoundButton.OnCheckedChangeListener {
  CheckBox cb;

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

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

  public void onCheckedChanged(CompoundButton buttonView,
                               boolean isChecked) {
    if (isChecked) {
      cb.setText(R.string.checked);
    }
    else {
      cb.setText(R.string.unchecked);
    }
  }
}

What I’m having trouble in understanding is how exactly this line works with this parameter being passed in

cb.setOnCheckedChangeListener(this);

Also, the method onCheckedChanged is not being explicitly called anywhere, how does Android make the connection to connect the checkbox state to the method name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:30:52+00:00Added an answer on June 16, 2026 at 9:30 pm

    You are implementing the interface and onCheckedChanged() is in your code. Your Activity now is also the Listener.

    When you implement an interface, you also have to override the methods specified by the interface. This means that the class that implements the interface can now act as an instance of that interface.

    public class CheckBoxDemo extends Activity implements
    CompoundButton.OnCheckedChangeListener {
    

    Your CheckBoxDemo class implements OnCheckedChangeListener so it can now act as an OnCheckedChangeListener if it is needed.

    Then later in your code you have

    public void onCheckedChanged
    

    Which is the method from the interface that CheckBoxDemo needs to implement for everything to work.

    Therefore, you can now use this (refering to your current CheckBoxDemo instance) to pass off to setOnCheckedChangeListener () because all the prior conditions are met – Your Class can now successfully listen for check events.

    For more information, read up on Interfaces from the java tutorials.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class XPBN extends Activity{ private Map _map; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
public class MainActivity extends Activity { Button b; //FrameLayout fl; @Override protected void onCreate(Bundle
public class ListView extends ListActivity { static String item; public void onCreate(Bundle icicle) {
public class AycanClass extends AsyncTask<String, Void, String> implements IAppointments { Activity activity; public AycanClass(Activity
public class HttpPostTask extends AsyncTask<Void, Integer, Void> { TextView txtStatus = (TextView)findViewById(R.id.txtStatus); @Override protected
public class tryAnimActivity extends Activity { /** * The thread to process splash screen
public class TwitterActivity extends Activity { private Twitter twitter; private OAuthProvider provider; private CommonsHttpOAuthConsumer
public class ImportContactsActivity extends Activity { /** Called when the activity is first created.
public class MyActivity extends Activity { /** Called when the activity is first created.
public class TomcatStopListener implements ServletContextListener { public void contextDestroyed(ServletContextEvent arg0) { // How to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.