转载:http://blog.csdn.net/lmj623565791/article/details/23382805

今天没事跟群里面侃大山,有个哥们说道Android Wheel这个控件,以为是Andriod内置的控件,google一把,发现是个github上的一个控件。

下载地址:https://code.google.com/p/android-wheel/    发现很适合做省市县三级联动就做了一个。

先看下效果图:

1、首先导入github上的wheel项目

2、新建个项目,然后选择记得右键->Properties->Android中将wheel添加为lib:

上面两个步骤是导入所有开源项目的过程了。

3、下面开始代码的编写:首先是省市区的json文件,放置在asserts的city.json中:

大概的格式先了解一下,一会代码会根据这样的格式解析

  1. {"citylist":
  2. [{"p":"河北",
  3. "c":[{"n":"石家庄",
  4. "a":[{"s":"长安区"},{"s":"桥东区"},{"s":"鹿泉市"}]
  5. }]
  6. }

4、布局文件,比较简单就3个WheelView分别代表省,市,县,还有一个按钮:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="#000000"
  6. android:orientation="vertical" >
  7. <TextView
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_gravity="center"
  11. android:layout_margin="10dp"
  12. android:text="请选择城市"
  13. android:textColor="#ffffff"
  14. android:textSize="20sp" />
  15. <LinearLayout
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content"
  18. android:background="@drawable/layout_bg"
  19. android:orientation="horizontal" >
  20. <kankan.wheel.widget.WheelView
  21. android:id="@+id/id_province"
  22. android:layout_width="0dp"
  23. android:layout_height="wrap_content"
  24. android:layout_weight="1" >
  25. </kankan.wheel.widget.WheelView>
  26. <kankan.wheel.widget.WheelView
  27. android:id="@+id/id_city"
  28. android:layout_width="0dp"
  29. android:layout_height="wrap_content"
  30. android:layout_weight="1" >
  31. </kankan.wheel.widget.WheelView>
  32. <kankan.wheel.widget.WheelView
  33. android:id="@+id/id_area"
  34. android:layout_width="0dp"
  35. android:layout_height="wrap_content"
  36. android:layout_weight="1" >
  37. </kankan.wheel.widget.WheelView>
  38. </LinearLayout>
  39. <Button
  40. android:onClick="showChoose"
  41. android:layout_gravity="right"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:text="确定"
  45. />
  46. </LinearLayout>

5、Activity的编写:注释相当详细,节不赘述了。

红色部分是我转载过修复的bug部分

源码下载点击这里

Android 省市县 三级联动(android-wheel的使用)[转]的更多相关文章

  1. Android 省市县 三级联动(android-wheel的使用)

    转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/23382805 今天没事跟群里面侃大山,有个哥们说道Android Wheel这个 ...

  2. android:省市县三级联动(基于json和spring)

    一.请看效果图": 二.程序的代码: 1.MainActivity.java package com.loveplusplus.loader.demo.ui; import org.json ...

  3. jQuery - 全国省市县三级联动

    最近有空用jquery做了一个全国省市县的三级联动,在以后或许可以用的到 ,遗憾的是我还没用封装,等有空看能不能封装成一个插件 废话不多说,贴上代码: <!doctype html> &l ...

  4. wex5 实战 省市县三级联动与地址薄同步

    无论是商城,还是快递,都要用到省市县三级联动,和地址薄,今天就以实战来制作,难点有3个: 1:三级联动,有wex5组件实现,相对简单,实战里对行数据进行了拼接 2:  地址薄选项,利用inputSel ...

  5. 省市县三级联动 sql语句

    发现在网上的省市县三级联动大部分是mysql的.就算是sqlserver的,也不准确.于是就把mysql的给改了下,适用sqlserver.sql语句如下: CREATE TABLE Dic_Area ...

  6. php仿经典省市县三级联动

    之前有个需求要写个类似省市县三级联动的页面,于是,网上找了点资料看了下,其实原理很简单: 当我们选择一级栏目中某条记录的时候,会获取该栏目的vaule值,并发起ajax请求,后台根据这个vaule值, ...

  7. 项目总结01:JSP mysql SpringMvc下中国省市县三级联动下拉框

    JSP mysql SpringMvc下中国省市县三级联动下拉框 关键词 JSP  mysql数据库  SpringMvc  ajax   Controller层  Service层  中国地区  省 ...

  8. Day 16 之二 省市县三级联动

    摘录自:雨神,供参考! province_dic = { "河北": { "石家庄": ["鹿泉", "藁城", &qu ...

  9. 省市县三级联动js代码

    省市县三级联动菜单,JS全国省市县(区)联动代码,一般可以用于用户注册或分类信息二手交易网站,需要的朋友直接复制代码就可以用了,不过有朋友反馈说缺少某些城市,具体缺少哪个尚不知,请想用的朋友自己补全吧 ...

随机推荐

  1. 【cogs858】磁性链

    [题目描述] 有N块编号为1~N的特殊磁石相互吸附组成一条磁性链,只有它们紧挨着时才会传递吸力,他们之间的吸力很大,如果我们要从N块相连的磁石中取出一块,那么需要消耗N-1个单位的能量,空缺处不再有吸 ...

  2. [转]我的第一个WCF

    1:首先新建一个解决方案 2:右击解决方案添加一个控制台程序 3:对着新建好的控制台程序右击添加wcf服务 最后的结果: 有3个文件 app.config  Iwcf_server.cs wcf_se ...

  3. ComboBoxEdit

    1.  如何使其不可编辑 TextEditStyle 设置为:DisableTextEditor 2.  如何设置鼠标为手形 Cursor 设置为:Hand

  4. extjs下拉框添加复选框

    给ComboBox组件配置listConfig 下拉框代码: var gyslxcm = Ext.create('Ext.form.field.ComboBox',{ id : 'gyslxcm', ...

  5. 高德地图关键字搜索删除上一次搜索的Marker

    方法:Marker类的  setMap(null);方法 高德是通过循环调用addmarker(i,d)方法  创建marker标记,所以我们需要 把创建的marker标记压入到一个数组,再第二次搜索 ...

  6. nginx 要改进的地方基础

  7. 提供进销存、ERP系统快速开发框架源码 (C#+SQL)

    C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4.0.htm 视频下载: 百度 ...

  8. QLabel

    The QLabel widget provides a text or image display. Content  Setting Plain text  Pass a QString to s ...

  9. BZOJ 1025 游戏

    Description windy学会了一种游戏.对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应.最开始windy把数字按顺序1,2,3,……,N写一排在纸上.然后再在这一排下面写上它们对 ...

  10. oracle 中使用触发器自动生成UUID

    create or replace trigger tri_test before insert on test for each row declare begin if :new.uuid is ...