膨胀视图android后根据数据库识别id单选按钮

但。约翰

我有3个文件。第一个 MainActivity.java,第二个是 activity_main.xml,第三个是 radio_button.xml。

这是radio_button.xml。我在这个文件中创建了 radioGroup 和 radioButton 。

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RadioGroup
    android:id="@+id/radioGroupNotes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RadioButton
        android:id="@+id/radioChildNotes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No respond to phone call"
        android:checked="false" />

</RadioGroup>
</LinearLayout>

这是活动_main。我在这个 xml 中创建了 LinearLayout。因为我想在这个 LinearLayout 中膨胀 radio_button.xml。

 <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
 <LinearLayout
            android:id="@+id/layoutRadioNotes"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </LinearLayout>
</LinearLayout>

这是 MainActivity.java。我只是把 main 函数放在这个文件中。

void showRadioNote(){
    layoutRadioNotes.removeAllViews();
    if(noteArray.size() != 0 ){
        for(int i=0;i<noteArray.size();i++){
            final View view = View.inflate(this, R.layout.radio_button, null);
            layoutRadioNotes.addView(view);
            final RadioGroup radioGroupNotes = (RadioGroup) view.findViewById(R.id.radioGroupNotes);
            final RadioButton radioChildNotes = (RadioButton) view.findViewById(R.id.radioChildNotes);

            radioChildNotes.setText(noteArray.get(i));


        }
    }
}

我已经可以在 noteArray 中显示所有数据了。但问题是如果我单击所有单选按钮,它会检查所有。我想让它只能选择一个,这意味着如果我点击第一个 radioButton ,那么它会检查 firstButton 并获取 value firstbutton,然后当我点击第二个 radioButton 时,它将取消选中 firstbutton 并检查第二个按钮并获取 secondbutton 的值。

这是我的问题,当单击其他单选按钮时,它没有取消选中其他按钮

萨达特

试试下面的代码,

public class MainActivity extends AppCompatActivity {

LinearLayout layoutRadioNotes;
ArrayList<String> noteArray = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    layoutRadioNotes = (LinearLayout) findViewById(R.id.layoutRadioNotes) ;
    noteArray.add("test 1");
    noteArray.add("test 1");
    showRadioNote();
}

void showRadioNote(){
    layoutRadioNotes.removeAllViews();
    if(noteArray.size() != 0 ){
        final View view = View.inflate(this, R.layout.radio_button, null);
        layoutRadioNotes.addView(view);

        final RadioGroup radioGroupNotes = (RadioGroup) view.findViewById(R.id.radioGroupNotes);
        radioGroupNotes.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // checkedId is the RadioButton selected
            }
        });
        for(int i=0;i<noteArray.size();i++){
            final RadioButton radioChildNotes = new RadioButton(this);
            radioChildNotes.setText(noteArray.get(i));
            radioGroupNotes.addView(radioChildNotes);

        }
    }
}

}

活动_main.xml

    <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layoutRadioNotes"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.moduletest.MainActivity">


</LinearLayout>

你按钮布局,

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

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/radioGroupNotes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

PHP使用单选按钮ID更新数据库列

来自分类Dev

从数据库填充选中的单选按钮

来自分类Dev

根据从JSP中从数据库检索的值检查单选按钮并选择下拉列表

来自分类Dev

根据单选按钮值将值存储在sqlite数据库的多个表中

来自分类Dev

根据从JSP中从数据库检索的值检查单选按钮并选择下拉列表

来自分类Dev

根据从数据库中读取的文本值检查RadioButtonList中的单选按钮

来自分类Dev

如何使用ID将多个单选按钮值更新到数据库

来自分类Dev

Android根据ListView ID从数据库获取单行

来自分类Dev

从数据库检索每行数据的单选按钮

来自分类Dev

ANDROID - 如何从单选按钮获取文本并将其插入到 sqlite 数据库?

来自分类Dev

在Javafx中从数据库填充表视图后,按钮停止工作

来自分类Dev

如何将单选按钮的值插入数据库?

来自分类Dev

将考勤单选按钮提交到数据库

来自分类Dev

单选按钮值未存储在数据库中

来自分类Dev

在数据库中插入单选按钮值

来自分类Dev

显示从数据库C#中选择的单选按钮

来自分类Dev

在数据库中插入单选按钮值

来自分类Dev

从数据库检索时更改单选按钮的值

来自分类Dev

将值从单选按钮传递到数据库

来自分类Dev

验证取决于数据库中值的单选按钮

来自分类Dev

使用单选按钮增加MySql数据库中的值

来自分类Dev

从数据库中检索存储的单选按钮值

来自分类Dev

在数据库中插入单选按钮值

来自分类Dev

单选按钮值未插入数据库

来自分类Dev

开关量(单选按钮)值到数据库

来自分类Dev

填充单选按钮并提交值以查询数据库

来自分类Dev

jsp中单选按钮中的数据库更改

来自分类Dev

从2列数据库中给出单选按钮标签

来自分类Dev

OnClick 提交将单选按钮值插入数据库

Related 相关文章

  1. 1

    PHP使用单选按钮ID更新数据库列

  2. 2

    从数据库填充选中的单选按钮

  3. 3

    根据从JSP中从数据库检索的值检查单选按钮并选择下拉列表

  4. 4

    根据单选按钮值将值存储在sqlite数据库的多个表中

  5. 5

    根据从JSP中从数据库检索的值检查单选按钮并选择下拉列表

  6. 6

    根据从数据库中读取的文本值检查RadioButtonList中的单选按钮

  7. 7

    如何使用ID将多个单选按钮值更新到数据库

  8. 8

    Android根据ListView ID从数据库获取单行

  9. 9

    从数据库检索每行数据的单选按钮

  10. 10

    ANDROID - 如何从单选按钮获取文本并将其插入到 sqlite 数据库?

  11. 11

    在Javafx中从数据库填充表视图后,按钮停止工作

  12. 12

    如何将单选按钮的值插入数据库?

  13. 13

    将考勤单选按钮提交到数据库

  14. 14

    单选按钮值未存储在数据库中

  15. 15

    在数据库中插入单选按钮值

  16. 16

    显示从数据库C#中选择的单选按钮

  17. 17

    在数据库中插入单选按钮值

  18. 18

    从数据库检索时更改单选按钮的值

  19. 19

    将值从单选按钮传递到数据库

  20. 20

    验证取决于数据库中值的单选按钮

  21. 21

    使用单选按钮增加MySql数据库中的值

  22. 22

    从数据库中检索存储的单选按钮值

  23. 23

    在数据库中插入单选按钮值

  24. 24

    单选按钮值未插入数据库

  25. 25

    开关量(单选按钮)值到数据库

  26. 26

    填充单选按钮并提交值以查询数据库

  27. 27

    jsp中单选按钮中的数据库更改

  28. 28

    从2列数据库中给出单选按钮标签

  29. 29

    OnClick 提交将单选按钮值插入数据库

热门标签

归档