ListView配合RadioButton实现单选列表

本文介绍如何在ListView中实现单选功能。通过设置ListView的singleChoice模式,并结合RadioButton,自定义控件以响应点击事件。适配器代码中处理选中状态,并通过setOnItemClickListener监听选中项的position。
摘要由CSDN通过智能技术生成

ListView中自带选择模式,这里是要实现单选,所以设置listview属性为singlechoice,为单选模式,Listview布局如下:

<ListView
    android:id="@+id/lv_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:choiceMode="singleChoice"
    android:dividerHeight="1dp"
    android:divider="#e1e1e1"/>
item的布局如下,就一个TextView加上一个RadioButton

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:padding="20dp"
    android:gravity="center_vertical">

    <TextView
        android:id="@+id/tv_item"
        android:layout_width="wrap_content"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值