本文介绍了原因接收和QUOT; RadioGroup中是不适用的论点"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行 RadioGroup中在我的应用即可。对于我已导入进口android.widget.RadioGroup 实施OnCheckedChangeListener 。不过还是我得到这个错误:

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

    }



}
解决方案

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

这篇关于原因接收和QUOT; RadioGroup中是不适用的论点"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 16:10