user3041524
user3041524

Reputation: 135

The method setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener)is not applicable

i was trying with a program ie depending on the button and radiobutton press the color ot the text area should change.the program is ok with the button it is running als0.but when i tried with the radio button it shows an error on this part

 r1.setOnCheckedChangeListener(this);

the following activity class is been attached

public class MainActivity extends Activity implements OnClickListener {
    Button b1;
    Button b2;
    Button b3;
    RadioButton r1;
    RadioButton r2;
    RadioButton r3;
    private View mColorRegion;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mColorRegion = findViewById(R.id.textView1);
                        b1 = (Button)findViewById(R.id.button1);
                        b2 = (Button)findViewById(R.id.button2);
                        b3 = (Button)findViewById(R.id.button3);
                        r1 =(RadioButton)findViewById(R.id.radio0);
                    r2 =(RadioButton)findViewById(R.id.radio1);
                    r3 =(RadioButton)findViewById(R.id.radio2);
                b1.setOnClickListener(this);
                b2.setOnClickListener(this);
                b3.setOnClickListener(this);
                r1.setOnCheckedChangeListener(this);}
        @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        if(arg0==b1)
        {
        mColorRegion.setBackgroundColor(Color.RED);
        }
        if(arg0==b2)
        {
        mColorRegion.setBackgroundColor(Color.GREEN);

        }
        if(arg0==b3)
        {
        mColorRegion.setBackgroundColor(Color.BLUE);
        }}
        public void onRadioButtonClicked(View arg1)
                {
                if(arg1==r1)
        {
        mColorRegion.setBackgroundColor(Color.RED);
        }
                if(arg1==r2)
        {
        mColorRegion.setBackgroundColor(Color.GREEN);
        }if(arg1==r3)
        {
        mColorRegion.setBackgroundColor(Color.BLUE);
        }}}

Upvotes: 0

Views: 339

Answers (1)

Raghunandan
Raghunandan

Reputation: 133560

You need to import

import android.widget.RadioGroup.OnCheckedChangeListener;

instead of

import android.widget.CompoundButton.OnCheckedChangeListener;

Edit:

I forgot to mention this as prosper k suggested

public class MainActivity extends Activity implements OnClickListener,OnCheckedChangeListener 

And override

@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {

}

Upvotes: 1

Related Questions