二级下拉列表菜单ExpandTabViews(仿团购app)
2016-02-15 18:05
246 查看
这里制作一个改进版,加深对Android相关界面技术的理解,如弹框PopWindow,自定义控件,自定义ToggleButton,回调机制.
实现效果如下图:
![](http://it.warmtel.com/wp-content/uploads/2015/12/ExpandTab.gif)
看了效果还是有兴趣吧,那么我们来看下如何使用
第一步准备数据源
价格,排序,优惠分别对应3个List集合
转载请注明来源:二级下拉列表菜单ExpandTabView改进版(仿美团,大众点评)
本文链接地址:http://it.warmtel.com/?p=1059
https://github.com/yihu0817/ExpandPopTabView
实现效果如下图:
![](http://it.warmtel.com/wp-content/uploads/2015/12/ExpandTab.gif)
看了效果还是有兴趣吧,那么我们来看下如何使用
第一步准备数据源
价格,排序,优惠分别对应3个List集合
private List<KeyValueBean> mPriceLists; //价格 private List<KeyValueBean> mSortLists; //排序 private List<KeyValueBean> mFavorLists; //优惠 区域涉及到有二级需要定义两个List集合
private List<KeyValueBean> mParentLists = new ArrayList<>();//父区域 private List<ArrayList<KeyValueBean>> mChildrenListLists = new ArrayList<>();//子区域 注:KeyValueBean对象定义如下 class KeyValueBean { private String key; private String value; } 第二步 引入android-expandpoptab-libary包 第三方包下载请移步这里DownLoad. 在你的Activity布局文件中使用自定义控件ExpandPopTabView
<com.warmtel.expandtab.ExpandPopTabView android:id="@+id/expandtab_view" android:layout_width="match_parent" android:layout_height="wrap_content" />
第三步 制作需要弹出的View,这里使用第三方包中默认实现View,PopOneListView和PopTwoListView PopOneListView popOneListView= new PopOneListView(this); PopTwoListView popTwoListView = new PopTwoListView(this); 第四步 ExpandPopTabView关联数据源和弹出View
popOneListView.setCallBackAndData(lists, expandTabView, new PopOneListView.OnSelectListener() { @Override public void getValue(String key, String value) { //弹出框选项点击选中回调方法 } }); expandTabView.addItemToExpandTab(defaultShowText, popViewOne); popTwoListView.setCallBackAndData(expandTabView, parentLists, childrenListLists, new PopTwoListView.OnSelectListener() { @Override public void getValue(String showText, String parentKey, String childrenKey) { //弹出框选项点击选中回调方法 } }); expandTabView.addItemToExpandTab(defaultShowText, distanceView); 你也可以设置弹出菜单默认选中项 popOneListView.setDefaultSelectByValue(defaultSelect); popTwoListView.setDefaultSelectByValue(defaultParentSelect, defaultChildSelect); 最后我们来对代码封装下添加两个方法 public void addItem(ExpandPopTabView expandTabView, List<KeyValueBean> lists, String defaultSelect, String defaultShowText) { PopOneListView popOneListView = new PopOneListView(this); popOneListView.setDefaultSelectByValue(defaultSelect); //popViewOne.setDefaultSelectByKey(defaultSelect); popOneListView.setCallBackAndData(lists, expandTabView, new PopOneListView.OnSelectListener() { @Override public void getValue(String key, String value) { //弹出框选项点击选中回调方法 } }); expandTabView.addItemToExpandTab(defaultShowText, popOneListView); } public void addItem(ExpandPopTabView expandTabView, List<KeyValueBean> parentLists, List<ArrayList<KeyValueBean>> childrenListLists, String defaultParentSelect, String defaultChildSelect, String defaultShowText) { PopTwoListView popTwoListView = new PopTwoListView(this); popTwoListView.setDefaultSelectByValue(defaultParentSelect, defaultChildSelect); //distanceView.setDefaultSelectByKey(defaultParent, defaultChild); popTwoListView.setCallBackAndData(expandTabView, parentLists, childrenListLists, new PopTwoListView.OnSelectListener() { @Override public void getValue(String showText, String parentKey, String childrenKey) { //弹出框选项点击选中回调方法 } }); expandTabView.addItemToExpandTab(defaultShowText, popTwoListView); } 调用方式 ExpandPopTabView expandTabView = (ExpandPopTabView) findViewById(R.id.expandtab_view); addItem(expandTabView, mPriceLists, "", "价格"); addItem(expandTabView, mFavorLists, "默认", "排序"); addItem(expandTabView, mSortLists, "优惠最多", "优惠"); addItem(expandTabView, mParentLists, mChildrenListLists, "锦江区", "合江亭", "区域");
转载请注明来源:二级下拉列表菜单ExpandTabView改进版(仿美团,大众点评)
本文链接地址:http://it.warmtel.com/?p=1059
https://github.com/yihu0817/ExpandPopTabView
相关文章推荐
- Android - 电话拦截
- 简介Android应用中sharedPreferences类存储数据的用法
- iOS 提交时显示 Valid signing identity not found 证书的签发者无效
- iOS学习之Objective-C 2.0 运行时系统编程
- Unity3D 播放MP4 的几种状态
- Android传感器及使用方法
- ios 分辨率 和物理大小
- swift 之脚本开发
- swift记录
- Aspects iOS的AOP面向切面编程的库
- Android蓝牙应用开发
- android 实现有阻尼下拉/上拉刷新列表
- 新建android项目报错import android.support.v7.app.ActionBarActivity;错误
- iOS支付宝接口调用总结
- android.support.design
- 我在Mac OS X 操作系统上搭建Android开发环境的经历
- android 自定义View Caused by: java.lang.ClassNotFoundException: Didn't find class
- iOS-延迟操作方法总结
- IOS支付宝支付步骤
- IOS开发证书显示“此证书的签发者无效”