自定义Radio样式配合ListView

CustomizeRadioActivity.java

package com.mw.app.view.activity;

import android.os.Bundle;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.mw.app.R;

import java.util.ArrayList;

public class CustomizeRadioActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.customize_radio_layout);
        //初始化数据
        ArrayList listData = new ArrayList<>();
        for (int i = 0; i < 13; i++) {
            listData.add("单选"+i);
        }
        //初始化ListView
       ListView listView = (ListView) findViewById(R.id.customize_radio_layout_listview);
        //设置选择模式 通过listView设置单选模式
        listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

        //创建adapter,布局加载系统默认的单选框  -- 想自己写ui,重写一个xml ui文件就OK
        ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_single_choice);
        arrayAdapter.addAll(listData);
        listView.setAdapter(arrayAdapter);
    }

}


    

 

自定义Radio样式配合ListView_第1张图片

 

 

你可能感兴趣的:(Android,radiobutton,listview,ui)