Android应用软件开发|Android自定义单选多选下拉列表

发疯的产品要做一个可以单选和多选的下拉列表,陪你玩玩吧。 直接上效果:
Android应用软件开发|Android自定义单选多选下拉列表
文章图片

实现方案:
我的思路是自定义一个类继承PopupWindow,里面的选项采用Listview,再结合一些动画来实现。
核心代码:

public class MultiSelectPopupWindows extends PopupWindow {private Context context; private View parent; private List data; private int yStart; private SearchPopupWindowsAdapter adapter; public MultiSelectPopupWindows(Context context, View parent, int yStart, List data) { this.context = context; this.parent = parent; this.yStart = yStart; this.data = https://www.it610.com/article/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 data) { adapter = new SearchPopupWindowsAdapter(context); adapter.setItems(data); listView.setAdapter(adapter); }public List getItemList() { return adapter.getItemList(); }}

项目源码:
【Android应用软件开发|Android自定义单选多选下拉列表】https://github.com/hfrommane/MultiSelectPopupWindows

    推荐阅读