2013-02-01 207 views
1

我有Dynmically做了CheckBox特定情况下做的CheckBox的Click事件,我想用CheckBox.OnCheckChanged 但Showig我的错误,你可以在情况下使用的fthis 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); 

         } 

我已经使用这个为复选框Changed事件

cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){ 

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

      } 
     }); 

错误:

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

我该如何解决这个问题?

在setOnCheckedChangeListener
+0

所有的“==”是你的第一个条件没用。请删除它们以提高可读性(另外,我会建议使用一组字符串和“包含”方法) – njzk2

+0

已经完成但我如何使用我的Checked Changed Listner,如问题 –

+2

中所述,与此http://类似stackoverflow.com/questions/8386832/android-checkbox-listener – Meghana

回答

0

()u需要通过()匿名类为CompoundButton.OnCheckedChangeListener