入门单选按钮不能被解析为一个类型 [英] Getting RadioButton cannot be resolved to a type

查看:364
本文介绍了入门单选按钮不能被解析为一个类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个单选按钮输入的活动。我做过什么描述
http://developer.android.com/guide/topics/ui/controls /radiobutton.html

但我正在逐渐单选按钮不能被解析为一个类型错误
布尔查=((单选)查看).isChecked();线。我得到的((单选)查看)的一部分红线。我很想念?请帮助。

 包com.my.test;    进口android.os.Bundle;
    进口android.app.Activity;
    进口android.content.Intent;
    进口android.view.Menu;
    进口android.view.View;
    进口android.widget.EditText;    公共类MAIN1延伸活动{
        @覆盖
        保护无效的onCreate(捆绑savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.main1);
        }        公共无效onRadioButtonClicked(查看视图){
            //是按钮现在检查?
            布尔查=((单选)查看).isChecked();
            int类型的; //存储该点击对应的单选按钮的值               开关(view.getId()){
                            案例R.id.radio1:
                                如果(选中)
                                 一个= 3;
                                    打破;
                            案例R.id.radio2:
                                如果(选中)一= 2;
                                    打破;
                            案例R.id.radio3:
                                如果(检查)A = 1;
                                    打破;
                            案例R.id.radio4:
                                如果(检查)A = 0;
                                    打破;
                     }               意向意图=新意图(这一点,Test2.class);
               intent.putExtra(inputValue将,一); //通A到下一个活动    }
        }


解决方案

以下行添加到您的类的顶部,与其他进口沿:

 进口android.widget.RadioButton;

有关备查,可以自动让Eclipse由pressing CTRL-Shift-O组合(Windows)或命令 - 增加进口转向-O (苹果机)

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       

    }
        }

解决方案

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)

这篇关于入门单选按钮不能被解析为一个类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆