最近做项目时,有个需求是在用户填写的个人资料中有个选择省市区的三级联动效果,通过一番查找,在github上找到一个不错的控件:PickerView。
github项目地址为:https://github.com/Bigkoo/Android-PickerView
控件使用起来非常简单,先上效果图:
使用PickerView前首先要添加依赖:
compile 'com.contrarywind:Android-PickerView:4.1.6'
布局文件也非常简单,可以根据需求更换View:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.a34413.pickerviewdemo.MainActivity">
<TextView
android:id="@+id/tv_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择地址"
android:layout_centerInParent="true" />
</RelativeLayout>
因为控件的数据格式必须要一个实体类:
public class JsonBean implements IPickerViewData {
private String name;
private List<CityBean> city;
public String getName() {
return name;
}
pub