如何在Android中使用WheelView实现三级联动

  介绍

这篇文章将为大家详细讲解有关如何在Android中使用WheelView实现三级联动,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

popupwindow中是三个WheelView,

& lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比;   http://schemas.android.com/apk/res/android" & lt; LinearLayout xmlns: android=?;   android:取向=皏ertical"   android:背景=? 00000000“;   android:重力=癰ottom"   android: layout_width=癿atch_parent"   android: layout_height=癿atch_parent"比;      LinearLayout & lt;   android: id=癅 + id/ly_myinfo_changeaddress_child"   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android: layout_alignParentBottom=皌rue"   android:背景=? ffffff"   android:取向=皏ertical"比;         & lt;使用   android: layout_width=癿atch_parent"   android: layout_height=?4 dp"   比;      & lt;视图   android:背景=癅color/silver"   android: layout_width=癿atch_parent"   android: layout_height=?.5 dp"/比;      & lt; TextView   android: id=癅 + id/btn_myinfo_cancel"   android: layout_width=皐rap_content"   android: layout_height=癿atch_parent"   android: paddingLeft=?8 dp"   android:文本=叭∠?   android:重力=癱enter"   android: layout_alignParentLeft=皌rue"   android: layout_marginRight=?5 dip"   输入textColor=癮ndroid: # e84515"   android: textSize=?4 sp"/比;         & lt; TextView   android: id=癅 + id/btn_myinfo_sure"   android: layout_width=皐rap_content"   android: layout_height=癿atch_parent"   android: layout_alignParentRight=皌rue"   android:重力=癱enter"   android:文本=巴瓿伞?   输入textColor=癮ndroid: # e84515"   android: paddingRight=?8 dp"   android: textSize=?4 sp"/比;      & lt;/RelativeLayout>      & lt;查看android: layout_width=癿atch_parent"   android: layout_height=? dp"   android:背景=? d8d8d8"/比;      LinearLayout & lt;   android: layout_width=癿atch_parent"   android: layout_height=?90 dip"   android:取向=癶orizontal"   android:重力=癱enter_vertical"比;      & lt; guozhaohui.com.wlylocationchoose.locationchoose.WheelView   android: id=癅 + id/provinceView"   android: layout_width=癿atch_parent"   android: layout_height=癿atch_parent"   android: layout_weight=?“/比;         & lt; guozhaohui.com.wlylocationchoose.locationchoose.WheelView   android: id=癅 + id/cityView"   android: layout_width=癿atch_parent"   android: layout_height=癿atch_parent"   android: layout_weight=?“/比;   & lt; guozhaohui.com.wlylocationchoose.locationchoose.WheelView   android: id=癅 + id/districtView"   android: layout_width=癿atch_parent"   android: layout_height=癿atch_parent"   android: layout_weight=?“/比;   & lt;/LinearLayout>      & lt;/LinearLayout>      & lt;/LinearLayout>

b。因为上面说了,需要将文件拷贝到应用目录下,所以直接最好这代码在应用程序中写,

包guozhaohui.com.wlylocationchoose;
  
  进口android.app.Application;
  
  进口java.io.InputStream;
  
  进口guozhaohui.com.wlylocationchoose.locationchoose.CityDataHelper;/* *
  *由$ {GuoZhaoHui}>视图popupView=LayoutInflater.from(这).inflate (R.layout.popup_locationchoose, null);
  mPopupWindow=new PopupWindow (popupView ViewGroup.LayoutParams。MATCH_PARENT ViewGroup.LayoutParams。WRAP_CONTENT,真正的);
  mPopupWindow.setTouchable(真正的);
  mPopupWindow.setFocusable(真正的);
  mPopupWindow.setOutsideTouchable(真正的);
  mPopupWindow.setAnimationStyle (R.style.popup_locationchoose_bottom);//pickText=(TextView) popupView.findViewById (R.id.tv_pickText);
  provinceView=(WheelView) popupView.findViewById (R.id.provinceView);
  cityView=(WheelView) popupView.findViewById (R.id.cityView);
  districtView=(WheelView) popupView.findViewById (R.id.districtView);//确定或者取消
  btn_myinfo_sure=(TextView) popupView.findViewById (R.id.btn_myinfo_sure);
  btn_myinfo_cancel=(TextView) popupView.findViewById (R.id.btn_myinfo_cancel);
  btn_myinfo_cancel.setOnClickListener(这个);
  btn_myinfo_sure.setOnClickListener(这);

设置三个wheelview的可见条目数

provinceView.setVisibleItems (7);   cityView.setVisibleItems (7);   districtView.setVisibleItems (7);

为三个wheelview添加滑动事件

如何在Android中使用WheelView实现三级联动