这篇文章主要为大家展示了“Android如何实现自定义单选多选下拉列表”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Android如何实现自定义单选多选下拉列表”这篇文章吧。
直接上效果:
实现方案:
我的思路是自定义一个类继承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(); }}
以上是“Android如何实现自定义单选多选下拉列表”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!