Reputation: 11
I am implementing RadioGroup in my application. For that I have imported import android.widget.RadioGroup
and implemented OnCheckedChangeListener
. But still I am getting this error:
The method setOnCheckedChangeListener(RadioGroup.OnCheckedChangeListener) in the type RadioGroup is not applicable for the arguments (OpenedClass)
Java:
OpenedClass.java
public class OpenedClass extends Activity implements OnClickListener,OnCheckedChangeListener{
TextView tv1,tv2;
RadioGroup selectionList;
Button rtn;
String gotBread;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
initlize();
Bundle gotBusket = getIntent().getExtras();
gotBread = gotBusket.getString("KEY");
tv1.setText(gotBread);
}
private void initlize() {
// TODO Auto-generated method stub
tv1 = (TextView)findViewById(R.id.tvQuestion);
tv2 = (TextView)findViewById(R.id.textView2);
rtn = (Button)findViewById(R.id.bReturn);
rtn.setOnClickListener(this);
selectionList = (RadioGroup)findViewById(R.id.rgAnswers);
selectionList.setOnCheckedChangeListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
switch(arg0.getId())
{
case R.id.rCrazy:
break;
case R.id.rSuper:
break;
case R.id.rBoth:
break;
}
}
}
Upvotes: 0
Views: 1943
Reputation: 17
During creating the oncheckedchangelistener(), specifying "new RadioGroup.OnCheckedChangeListener()
" instead of just "OnCheckedChangeListener()
" fixed the problem.
Adding the sample code for others reference.
RadioGroup rdGroup = (RadioGroup) findViewById(R.id.rdbGp1);
rdGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
}
});
Upvotes: 1
Reputation: 68167
You are importing an incorrect class of OnCheckedChangeListener
for RadioGroup
.
Replace:
import android.widget.CompoundButton.OnCheckedChangeListener;
with this one:
import android.widget.RadioGroup.OnCheckedChangeListener;
and fix your interface implementation as below:
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId)
{
//your cases
}
}
Upvotes: 5