1#
安卓Developer QQ群273843464欢迎您的加入~~
原文:http://blog.cfxixi.com/post/2012/10/17/%E5%AE%89%E5%8D%93%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8radioGroup%EF%BC%88radioButton%EF%BC%89%E4%BE%8B%E5%AD%90.aspx
一个判断选择题是否正确的例子(例子可取群共享下载)

TextView        m_TextView;
    RadioGroup        m_RadioGroup;
    RadioButton        m_Radio1, m_Radio2, m_Radio3, m_Radio4;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        m_TextView = (TextView) findViewById(R.id.TextView01);
        m_RadioGroup = (RadioGroup) findViewById(R.id.RadioGroup01);
        m_Radio1 = (RadioButton) findViewById(R.id.RadioButton1);
        m_Radio2 = (RadioButton) findViewById(R.id.RadioButton2);
        m_Radio3 = (RadioButton) findViewById(R.id.RadioButton3);
        m_Radio4 = (RadioButton) findViewById(R.id.RadioButton4);

        
        m_RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                // TODO Auto-generated method stub
                if (checkedId == m_Radio2.getId())
                {
                    DisplayToast("bb" + m_Radio2.getText() + "aaa");
                }
                else
                {
                    DisplayToast("111");
                }
            }
        });
    }
    

    public void DisplayToast(String str)
    {
        Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.TOP, 0, 220);
        toast.show();
    }
sadhs



页面布局样式:


    androidrientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        android:id="@+id/TextView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
      android:id="@+id/RadioGroup01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    androidrientation="vertical"
    android:layout_x="3px"
    android:layout_y="54px"
    >
          android:id="@+id/RadioButton1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton1"
    />
          android:id="@+id/RadioButton2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton2"
    />
          android:id="@+id/RadioButton3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton3"
    />
          android:id="@+id/RadioButton4"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton4"
    />