0

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

但是我在 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       

    }
        }
4

1 回答 1

3

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

import android.widget.RadioButton;

为了将来参考,您可以通过按ctrl-shift-O(Windows) 或command-shift-O(Mac)自动让 Eclipse 添加导入

于 2013-01-16T18:24:31.800 回答