Getting RadioButton cannot be resolved to a type

一世执手 提交于 2019-12-13 04:22:28

问题


I am trying to build a radio button input activity. I have done whatever described in http://developer.android.com/guide/topics/ui/controls/radiobutton.html

But I am getting "RadioButton cannot be resolved to a type" error in boolean checked = ((RadioButton) view).isChecked(); line. I am getting Red line under "((RadioButton) view)" part. What I am missing? Please help.

 package com.my.test;

    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.widget.EditText;

    public class Main1 extends Activity {


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main1);
        }

        public void onRadioButtonClicked(View view) {
            // Is the button now checked?
            boolean checked = ((RadioButton) view).isChecked();
            int a; // store the value corresponding to  the RadioButton which is clicked 

               switch(view.getId()) {
                            case R.id.radio1:
                                if (checked)
                                 a = 3;
                                    break;
                            case R.id.radio2:
                                if (checked) a = 2;
                                    break;
                            case R.id.radio3:
                                if (checked) a = 1;
                                    break;
                            case R.id.radio4:
                                if (checked) a = 0;
                                    break;
                     }

               Intent intent = new Intent(this, Test2.class);
               intent.putExtra("inputValue", a); // pass "a" to the next Activity       

    }
        }

回答1:


Add the following line to the top of your class, along with the other imports:

import android.widget.RadioButton;

For future reference, you can automatically have Eclipse add the imports by pressing ctrl-shift-O (Windows) or command-shift-O (Mac)



来源:https://stackoverflow.com/questions/14365077/getting-radiobutton-cannot-be-resolved-to-a-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!