1

您好,我正在开发 android 应用程序,我的应用程序上有几个单选按钮,当我单击单选按钮时,它可以执行我想要的操作,即显示网页,但是当我单击另一个单选按钮时,它充当检查盒子。这是我的代码:

RadioButton webss = (RadioButton) findViewById (R.id.studentsite);
    RadioButton webst = (RadioButton) findViewById (R.id.staffsite);
    RadioButton webbaak = (RadioButton) findViewById (R.id.baak);
webss.setOnClickListener(new RadioButton.OnClickListener()
    {
        public void onClick(View v)
            {
            callintent(v);
            }
    });

    webst.setOnClickListener(new RadioButton.OnClickListener()
    {
        public void onClick(View v)
            {
            callintent(v);
            }
    });

    webbaak.setOnClickListener(new RadioButton.OnClickListener()
    {
        public void onClick (View v)
            {
            callintent(v);
            }
    });
public void callintent(View view) 
{
    Intent intent = null;
    switch (view.getId())
    {
        case R.id.studentsite:
            intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://studentsite.gunadarma.ac.id"));
            startActivity(intent);
            break;
        case R.id.staffsite:
            intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://staffsite.gunadarma.ac.id"));
            startActivity(intent);
            break;
        case R.id.baak:
            intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://baak.gunadarma.ac.id"));
            startActivity(intent);
            break;
default:
            break;
    }

你有什么可以修复这些代码吗?谢谢。

4

3 回答 3

1

无论何时检查一个,您都需要将所有RadioButtons放入您的布局文件中,RadioGroup 只要检查一个,就会自动取消选中其他方式。

于 2012-08-24T09:10:41.753 回答
0

您需要在 xml 文件中的标记内添加这些单选按钮。像这样。 <RadioGroup> <RadioButton/> <RadioButton/> </RadioGroup>

于 2012-08-24T09:14:56.800 回答
0

使用无线电组。是一个很好的例子。

于 2012-08-24T09:14:59.237 回答