Android实现省市区三级联动

在Android项目中,为了实现省市区三级联动效果,开发者可以借助PickerView控件。通过引入依赖,设置布局,创建数据实体类,读取json数据,并在MainActivity中进行配置,即可轻松实现这一功能。
摘要由CSDN通过智能技术生成

最近做项目时,有个需求是在用户填写的个人资料中有个选择省市区的三级联动效果,通过一番查找,在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
评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值