您的位置:首页 > 其它

巧用CheckedTextView完成自定义radiobutton的listview

2017-08-02 19:44 232 查看
因为要用自定义图片的radiobutton的listview,最开始想自己重新写BaseAdapter,重新定义BaseAdapter中的每个list的item。总之android提供了太多方便的控件,就想用他自己的,所以我发现了CheckedTextView。

自己定义的layout文件

list_item_single_choice.xml

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

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@android:id/text1"

android:layout_width="match_parent"

android:layout_height="?android:attr/listPreferredItemHeight"

android:checkMark="@drawable/radiobuttonstyle

android:gravity="center_vertical"

android:paddingLeft="30dp"

android:paddingRight="30dp"

android:textAppearance="?android:attr/textAppearanceListItemSmall"

android:textColor="@color/textcolor_select"

android:textSize="22sp" />

其中checkmark就是自己定义radiobutton的drawable

radiobuttonstyle.xml定义如下

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

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:drawable="@drawable/system_seat_setting_on" android:state_checked="true"></item>

<item android:drawable="@drawable/system_seat_setting_on" android:state_selected="true"></item>

<item android:drawable="@drawable/system_seat_setting_on" android:state_pressed="true"></item>

<item android:drawable="@drawable/system_seat_setting_off"></item>

</selector>

这样自己就不需要重新写adapte了。

代码里实现如下

mListView.setAdapter(new ArrayAdapter<String>(context,R.layout.list_item_single_choice, Arraystring));

直接用了系统的ArrayAdapter就可以啦~~
http://www.cnblogs.com/candycaicai/p/3186243.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: