1

I have Dynmically MAde a CheckBox for a particular case, i want to use the CheckBox.OnCheckChanged But it Showig me error that you can use fthis in case of RadioGroup

if(sQuestionId.toString()=="518" || "518".equals(sQuestionId.toString()){

                    llCheckBoxQuestion=new LinearLayout(this);
                    llCheckBoxQuestion.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                    llCheckBoxQuestion.setOrientation(android.widget.LinearLayout.HORIZONTAL);

                    cb=new CheckBox(this);
                    cb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                    cb.setId(idCheckBox2);



                    String sQuestion=ele.getText(0);
                    tvQuestion=new TextView(this);
                    tvQuestion.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));


    tvQuestion.setText(sQuestion.replace("nbsp;","").replace("&", "").replace(">", "").replace("<", "").replace("BR", "\n"));
                    //  tvQuestion.setText(sQuestion.replace("&"," "));
                        tvQuestion.setTextColor(Color.WHITE);
                        tvQuestion.setTextSize(16);
                        tvQuestion.setGravity(Gravity.TOP);

                        llCheckBoxQuestion.addView(cb);
                        llCheckBoxQuestion.addView(tvQuestion);

                        ll.addView(tvTitle);
                        //ll.addView(tv);
                        ll.addView(llChild);
                      //ll.addView(tvQuestion);
                        ll.addView(llCheckBoxQuestion);

                        }

I have Used this for CheckBox Changed Event

cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){

            @Override
            public void onCheckedChanged(CompoundButton arg0,boolean arg1) {
                if(arg0.isChecked()){
                    fnCheckChanged(t1.getText().toString(),t3.getText().toString(),arg1,arg0);  
                }

            }
        });

Error :

The method setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener) in the type CompoundButton is not applicable for the arguments (new RadioGroup.OnCheckedChangeListener(){})

How can i solve this?

raghav chopra
  • 827
  • 3
  • 9
  • 25
  • all the '==' are useless in your first condition. please remove them to improve readbility (also, i would suggest using a Set of String and the `contains` method) – njzk2 Feb 01 '13 at 10:04
  • Well Already done that But How can i use my Checked Changed Listner as asked in Question – raghav chopra Feb 01 '13 at 10:06
  • 2
    similar to this http://stackoverflow.com/questions/8386832/android-checkbox-listener – Meghana Feb 01 '13 at 10:08
  • 2
    your import is wrong (but since you didn't care to post it, that's just a supposition) – njzk2 Feb 01 '13 at 10:17

1 Answers1

0

in the setOnCheckedChangeListener() u need to pass the anonymous class as CompoundButton.OnCheckedChangeListener()

Meghana
  • 93
  • 1
  • 1
  • 10