无法将RadioButton解析为某种类型

时间:2013-01-16 18:21:20

标签: android radio-button android-contentresolver

我正在尝试构建一个单选按钮输入活动。我做了所描述的任何事情 http://developer.android.com/guide/topics/ui/controls/radiobutton.html

但是我得到了#34; RadioButton无法解析为#34;错误 boolean checked =((RadioButton)view).isChecked();线。我在"((RadioButton)视图下)获得红线"部分。我错过了什么?请帮忙。

 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 个答案:

答案 0 :(得分:3)

将以下行添加到您的类的顶部,以及其他导入:

import android.widget.RadioButton;

为了将来参考,您可以通过按ctrl-shift-O(Windows)或command-shift-O(Mac)

自动让Eclipse添加导入