Android自定义单选多选下拉列表的实例代码
作者:Fun_He 时间:2022-06-08 15:53:33
发疯的产品要做一个可以单选和多选的下拉列表,陪你玩玩吧。
直接上效果:
实现方案:
我的思路是自定义一个类继承PopupWindow,里面的选项采用Listview,再结合一些动画来实现。
核心代码:
public class MultiSelectPopupWindows extends PopupWindow {
private Context context;
private View parent;
private List<Search> data;
private int yStart;
private SearchPopupWindowsAdapter adapter;
public MultiSelectPopupWindows(Context context, View parent, int yStart, List<Search> data) {
this.context = context;
this.parent = parent;
this.yStart = yStart;
this.data = data;
initView();
}
private void initView() {
View view = View.inflate(context, R.layout.popupwindows_multiselect, null);
view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in_slow));
LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayout_selector);
linearLayout.startAnimation(AnimationUtils.loadAnimation(context, R.anim.list_top_in));
ListView listView = (ListView) view.findViewById(R.id.listView_selector);
setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
setBackgroundDrawable(new BitmapDrawable());
setFocusable(true);
setOutsideTouchable(true);
setContentView(view);
showAtLocation(parent, Gravity.TOP, 0, DensityUtil.dip2px(context, yStart));
update();
initListView(listView, data);
}
private void initListView(ListView listView, List<Search> data) {
adapter = new SearchPopupWindowsAdapter(context);
adapter.setItems(data);
listView.setAdapter(adapter);
}
public List getItemList() {
return adapter.getItemList();
}
}
项目源码:https://github.com/hfrommane/MultiSelectPopupWindows
来源:http://blog.csdn.net/hfrommane/article/details/76304113
标签:Android,下拉列表
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
jdk源码阅读Collection详解
2022-07-25 08:57:40
Java FineReport报表工具导出EXCEL的四种方式
2021-07-20 02:58:17
![](https://img.aspxhome.com/file/2023/1/67451_0s.png)
Unity Shader实现裁切效果
2023-03-05 07:54:24
![](https://img.aspxhome.com/file/2023/3/94643_0s.jpg)
Spring+SpringMVC+MyBatis深入学习及搭建(一)之MyBatis的基础知识
2021-09-27 15:12:59
![](https://img.aspxhome.com/file/2023/3/66503_0s.png)
Apache Shrio安全框架实现原理及实例详解
2023-07-27 19:47:59
![](https://img.aspxhome.com/file/2023/5/75515_0s.png)
IDEA编译报错:Error:java:无效的源发行版:17的解决办法
2023-08-25 10:38:06
![](https://img.aspxhome.com/file/2023/3/62453_0s.png)
java递归实现拼装多个api的结果操作方法
2023-11-24 23:44:35
详解从零开始---用C#制作扫雷游戏
2022-06-14 13:33:12
![](https://img.aspxhome.com/file/2023/9/70399_0s.png)
Java利用apache ftp工具实现文件上传下载和删除功能
2022-03-17 02:04:01
FeignClient中name和url属性的作用说明
2023-06-04 13:21:55
MyBatis基础支持DataSource实现源码解析
2023-01-16 09:58:07
Linux下动静态库的打包与使用指南(C/C++)
2023-06-21 20:22:11
![](https://img.aspxhome.com/file/2023/8/68778_0s.png)
Java排序算法总结之希尔排序
2022-07-16 13:19:11
解决SpringMvc中普通类注入Service为null的问题
2023-10-29 01:23:25
Android实战教程第九篇之短信高效备份
2022-02-14 12:59:20
Spring配置shiro时自定义Realm中属性无法使用注解注入的解决办法
2022-09-18 11:18:22
![](https://img.aspxhome.com/file/2023/2/83122_0s.jpg)
关于Java实现HttpServer模拟前端接口调用
2021-07-10 07:44:17
![](https://img.aspxhome.com/file/2023/4/88054_0s.png)
Spring 与 JDK 线程池的简单使用示例详解
2023-08-20 04:02:59
Springboot通过run启动web应用的方法
2021-08-30 01:57:37
![](https://img.aspxhome.com/file/2023/7/64527_0s.png)
Java中Optional类及orElse方法详解
2022-07-12 03:21:36