如何在Android中对不同线性布局上的单选按钮进行分组

如何在Android中对不同线性布局上的单选按钮进行分组,android,radio-button,Android,Radio Button,我的问题是如何对这些单选按钮进行分组。它们位于不同的线性布局上,因为我填充屏幕的方式是执行for循环,以使ImageView和TextView就位 请帮帮我 这是密码 private void initialize() throws JSONException{ JSONObject json = new JSONObject(getIntent().getStringExtra("json")); candidates = json.getJSONArray("candidat

我的问题是如何对这些单选按钮进行分组。它们位于不同的线性布局上,因为我填充屏幕的方式是执行for循环,以使ImageView和TextView就位

请帮帮我

这是密码

private void initialize() throws JSONException{
    JSONObject json = new JSONObject(getIntent().getStringExtra("json"));
    candidates = json.getJSONArray("candidates");

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.vote_list, null);
    ScrollView sv = (ScrollView) v.findViewById(R.id.scrollviewlist);
    LinearLayout main_layout = new LinearLayout(this);
    main_layout.setOrientation(LinearLayout.VERTICAL);

    String fullname = null, position = null, image = null, prev = "";
    for(int i = 0; i<candidates.length();i++){
        JSONObject o = candidates.getJSONObject(i);

        fullname = o.getString("lastName") + ", " + o.getString("firstName");
        position = o.getString("positionName");
        image = o.getString("image");

        if(!position.equals(prev)){
            TextView pos = new TextView(this);
            pos.setText(position);
            pos.setTextSize(20);
            pos.setPadding(10, 0, 0, 0);
            main_layout.addView(pos);
        }

        LinearLayout child = new LinearLayout(this);
        child.setOrientation(LinearLayout.HORIZONTAL);
        child.setPadding(15, 5, 5, 5);
        child.setGravity(Gravity.CENTER_VERTICAL);

        TextView name = new TextView(this);
        name.setText(fullname);
        name.setTextSize(13);
        name.setPadding(10, 0, 0, 0);
        name.setWidth(210);

        RadioButton rb = new RadioButton(this);
        rb.setText("Vote");

        ImageView profImage = new ImageView(this);
        profImage.setAdjustViewBounds(true);
        profImage.setMaxHeight(60);
        profImage.setMaxWidth(60);
        if(image.equals(""))
            profImage.setImageResource(R.drawable.profile);
        else{
            Bitmap bmp;
            byte[] img = Base64.decode(image.toString(), Base64.DEFAULT);
            bmp = BitmapFactory.decodeByteArray(img, 0, img.length);
            profImage.setImageBitmap(bmp);
        }

        child.addView(profImage);
        child.addView(name);
        child.addView(rb);

        main_layout.addView(child);

        prev = position;
    }
    sv.addView(main_layout);
    setContentView(v);
}
private void initialize()抛出JSONException{
JSONObject json=新的JSONObject(getIntent().getStringExtra(“json”);
候选者=json.getJSONArray(“候选者”);
LayoutFlater充气器=(LayoutFlater)getSystemService(Context.LAYOUT\u充气器\u服务);
视图v=充气机。充气(R.layout.vote_列表,空);
ScrollView sv=(ScrollView)v.findViewById(R.id.scrollviewlist);
线性布局主布局=新的线性布局(本);
主布局。设置方向(线性布局。垂直);
字符串fullname=null,position=null,image=null,prev=”“;

对于(int i=0;i在布局文件中使用以下xml元素:

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

            <RadioButton
                android:id="@+id/RadioButton_branchSearch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Branch Search" 
                android:checked="true" />

            <RadioButton
                android:id="@+id/RadioButton_ifscSearch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="IFSC code search" />

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

            <RadioButton
                android:id="@+id/RadioButton_branchSearch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Branch Search" 
                android:checked="true" />

            <RadioButton
                android:id="@+id/RadioButton_ifscSearch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="IFSC code search" />

        </RadioGroup>
RadioGroup_searchType=(RadioGroup)rootView.findViewById(R.id.RadioGroup_searchType);
RadioGroup_searchType.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) 
    {
        switch (checkedId) 
        {
            case R.id.RadioButton_branchSearch:
            break;
            case R.id.RadioButton_ifscSearch:
            break;
        };
    }
});