【问题标题】:Multiple errors with Radio Group in androidandroid中无线电组的多个错误
【发布时间】:2013-06-07 22:18:20
【问题描述】:

我收到以下错误: 传递 XML 时出错:未绑定前缀 属性缺少 android 命名空间前缀 我三合会添加:xmlns:android但它不会识别它 代码:

<RadioGroup 

andorid:orientation = "vertical"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
andorid:layout_weight = "1"
>


    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />
    </RadioGroup>

【问题讨论】:

  • 你不能为每个按钮设置相同的 id,使用不同的 id´s
  • 只做其他事情大约 10 分钟,然后再次查看文件(提示:拼写)
  • @MichaelButscher 非常感谢,我盯着这段代码看了 20 分钟,终于明白了

标签: android xml radio-group


【解决方案1】:

首先,您必须为您的按钮设置不同的 ID:

    <RadioGroup 

 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_weight="1"
 >


<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="RadioButton" />

<RadioButton
    android:id="@+id/radioButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="RadioButton" />

<RadioButton
    android:id="@+id/radioButton3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="RadioButton" />
</RadioGroup>

其次...这是整个 xml 吗?你必须设置

    <?xml version="1.0" encoding="utf-8"?>

在开头和

    xmlns:android="http://schemas.android.com/apk/res/android"

到广播组

【讨论】:

  • 一秒钟后对链接发表评论
【解决方案2】:

如果您更改 RadioButtons Id,它会起作用!。 =D

【讨论】:

    【解决方案3】:
    I expect below code works 100%
    <?xml version="1.0" encoding="utf-8"?>
    <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:orientation="vertical">
    
    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />
    
    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />
    
    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />
    
    </RadioGroup>
    

    您可以使用 android:weightSum="" 代替 android:layout_weight="" 。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 2013-09-03
      • 1970-01-01
      相关资源
      最近更新 更多