2013-01-16 52 views
0

我正在尝试构建单选按钮输入活动。我已经做了一切在 http://developer.android.com/guide/topics/ui/controls/radiobutton.html获取RadioButton无法解析为类型

但我越来越描述“单选按钮不能被解析为一个类型”中 布尔检查=((单选)查看).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  

    } 
     } 
+0

您是否导入了RadioButton类? –

回答

3

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

import android.widget.RadioButton; 

对于未来的参考,你可以自动让Eclipse按ctrl-shift-O(Windows)中添加的进口或command-shift-O(Mac)