java - 我想通过选择该组的单选按钮来获取该组的ID,我正在动态创建这两个组

标签 java android arraylist

我正在动态创建单选按钮和单选按钮组,我希望通过选择该组的单选按钮来获取单选按钮组的ID,名称。我正在动态创建单选组和单选按钮。

String cat_mname= getIntent().getStringExtra("cat_name");


String Radio_button_loop= getIntent().getStringExtra("Radio_button_loop");

 int Radio_button_to_int = Integer.parseInt(Radio_button_loop);
                            Toast.makeText(getApplicationContext(),Radio_button_loop,Toast.LENGTH_LONG).show();
                            ActionBar actionBar = getSupportActionBar();
                            actionBar.setTitle(cat_mname);

                            mlinearLayout = (LinearLayout) findViewById(R.id.values);


                            Cursor cursor = dbController.getdata("SELECT * FROM DATA4 WHERE catname = '"+cat_mname+"'");
                            arrayList.clear();

                            while (cursor.moveToNext())
                            {
                                int id = cursor.getInt(0);
                                String cat_name = cursor.getString(1);
                                String cat_option_value = cursor.getString(2);
                                String cat_type = cursor.getString(3);
                                String value = cursor.getString(4);



                                arrayList.add(new data_class(id,cat_name,cat_option_value,cat_type,value));
                            }

                            String aa[] = {"X","O","S","H"}; 
                these are radio button values for radio group
                            for (int k = 0; k < arrayList.size(); k++) {
                                //create text button
                                TextView title = new TextView(getApplicationContext());
                                title.setText(arrayList.get(k).getCat_name());
                             setting title
                                title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
                                title.setTextColor(Color.RED);
                                mlinearLayout.addView(title);
                                // create radio button
                                rb = new RadioButton(this);
                                rg = new RadioGroup(getApplicationContext());
                                rg.setId(arrayList.get(k).getId());
                here i am setting the id or text of radio group so i can get it.
          rg.setOrientation(RadioGroup.HORIZONTAL);

       for (int i = 0; i < Radio_button_to_int; i++) {
    // in this loop, i am creating radio buttons dynamically for radio groups.
                                        rb = new RadioButton(getApplicationContext());
                                        rg.addView(rb);
                                        rb.setText(aa[i]);
           here i am creating radio buttons for radiogroup

                                    }
                                    mlinearLayout.addView(rg);

                            }

                            rb.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {

here i want to get radio group value that i set above but its not returning.     }
                            });

最佳答案

试着做:
v.getParent()。getId();

关于java - 我想通过选择该组的单选按钮来获取该组的ID,我正在动态创建这两个组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56322217/

相关文章:

java - Weblogic 10.3开启管理员端口后无法访问

Android 布局我无法在同一行中正确定位三个项目

Android:MediaCodec+MediaMuxer 编码的音频 MP4 无法播放

java - 模型类对象列表中的数据未正确检索?

java - ArrayList<class> 交换方法

java - JPanel 组件在尝试刷新后消失

java - 谷歌数据流: Read unbound PCollection from Google Cloud Storage

java - button.OnClick 代码运行但不执行更改?

java - 为什么我的具有自定义布局的 fragment 不检查给定的checkedItem

java - 将可绘制对象的 ArrayList 发送到服务(Java、Android)