2013-04-02 34 views
0

我實現RadioGroup中在我的應用程序。爲此,我已導入import android.widget.RadioGroupimplemented OnCheckedChangeListener。不過還是我收到此錯誤:理由接受「RadioGroup中是不適用的論點」

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; 
     } 

    } 



} 

回答

5

要導入一個不正確的類的OnCheckedChangeListenerRadioGroup

替換:

import android.widget.CompoundButton.OnCheckedChangeListener; 

這一個:

import android.widget.RadioGroup.OnCheckedChangeListener; 

和解決如下的接口實現:

@Override 
public void onCheckedChanged(RadioGroup group, int checkedId) { 
    switch(checkedId) 
    { 
     //your cases 
    } 
} 
+1

啊.. :) – Lucifer

+0

你可能想用Ctrl + Shift + O從時間你定的進口時間,如果使用Eclipse IDE – Neo

+0

我可否知道這兩者之間有什麼區別? – user2235614

1

在創建oncheckedchangelistener(),指定 「new RadioGroup.OnCheckedChangeListener()」而不是僅僅「OnCheckedChangeListener()」修復了這個問題。

添加爲他人蔘考示例代碼。

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 

     } 
    }); 
0

您在很長一段時間後,導入不正確的類的 OnCheckedChangeListener