最新消息:欢迎访问Android开发中文站!商务联系QQ:1304524325

安卓实现类似京东淘宝的筛选功能,全网最简单方便

热点资讯 loading 926浏览 0评论

最近需要实现一个筛选的功能。但是在网上找了半天都写得特别乱,要不就是收费,今天做一个。实现效果图如下。

点击按钮直接弹出。可以放在任何控件下面。下面是使用代码:

</pre>
<div id="icon_container_left"><a id="edit_file" title="打开本地已存草稿,开始编辑,并自动保存"></a> <a id="export_file" title="导出带样式的HTML文件"></a> <a id="picture" title="上传图片,及图床设置"></a></div>
<div id="icon_container_right"><button id="copy_btn" data-clipboard-action="copy" data-clipboard-target="#render_output_id">复制</button> <a id="mycss_icon" title="可选css样式模板,或自定义css样式"></a>一键排版 <a id="color_ref" title="参考颜色"></a> 代码行数 <input id="codeline" type="checkbox" name="codelineName" /> 代码紧凑 <input id="narrowcode" type="checkbox" name="narrowcode" />
<div id="code_select"><label>代码主题:</label><select><option selected="selected" value="favorite">favorite</option><option value="agate">agate</option><option value="androidstudio">androidstudio</option><option value="arduino-light">arduino-light</option><option value="arta">arta</option><option value="ascetic">ascetic</option><option value="atelier-cave-dark">atelier-cave-dark</option><option value="atelier-cave-light">atelier-cave-light</option><option value="atelier-dune-dark">atelier-dune-dark</option><option value="atelier-dune-light">atelier-dune-light</option><option value="atelier-estuary-dark">atelier-estuary-dark</option><option value="atelier-estuary-light">atelier-estuary-light</option><option value="atelier-forest-dark">atelier-forest-dark</option><option value="atelier-forest-light">atelier-forest-light</option><option value="atelier-heath-dark">atelier-heath-dark</option><option value="atelier-heath-light">atelier-heath-light</option><option value="atelier-lakeside-dark">atelier-lakeside-dark</option><option value="atelier-lakeside-light">atelier-lakeside-light</option><option value="atelier-plateau-dark">atelier-plateau-dark</option><option value="atelier-plateau-light">atelier-plateau-light</option><option value="atelier-savanna-dark">atelier-savanna-dark</option><option value="atelier-savanna-light">atelier-savanna-light</option><option value="atelier-seaside-dark">atelier-seaside-dark</option><option value="atelier-seaside-light">atelier-seaside-light</option><option value="atelier-sulphurpool-dark">atelier-sulphurpool-dark</option><option value="atelier-sulphurpool-light">atelier-sulphurpool-light</option><option value="atom-one-dark">atom-one-dark</option><option value="atom-one-light">atom-one-light</option><option value="brown-paper">brown-paper</option><option value="codepen-embed">codepen-embed</option><option value="color-brewer">color-brewer</option><option value="darcula">darcula</option><option value="dark">dark</option><option value="darkula">darkula</option><option value="default">default</option><option value="docco">docco</option><option value="dracula">dracula</option><option value="far">far</option><option value="foundation">foundation</option><option value="github">github</option><option value="github-gist">github-gist</option><option value="googlecode">googlecode</option><option value="grayscale">grayscale</option><option value="gruvbox-dark">gruvbox-dark</option><option value="gruvbox-light">gruvbox-light</option><option value="hopscotch">hopscotch</option><option value="hybrid">hybrid</option><option value="idea">idea</option><option value="ir-black">ir-black</option><option value="kimbie.dark">kimbie.dark</option><option value="kimbie.light">kimbie.light</option><option value="magula">magula</option><option value="mono-blue">mono-blue</option><option value="monokai">monokai</option><option value="monokai-sublime">monokai-sublime</option><option value="obsidian">obsidian</option><option value="ocean">ocean</option><option value="paraiso-dark">paraiso-dark</option><option value="paraiso-light">paraiso-light</option><option value="pojoaque">pojoaque</option><option value="purebasic">purebasic</option><option value="qtcreator_dark">qtcreator_dark</option><option value="qtcreator_light">qtcreator_light</option><option value="railscasts">railscasts</option><option value="rainbow">rainbow</option><option value="routeros">routeros</option><option value="school-book">school-book</option><option value="solarized-dark">solarized-dark</option><option value="solarized-light">solarized-light</option><option value="sunburst">sunburst</option><option value="tomorrow">tomorrow</option><option value="tomorrow-night">tomorrow-night</option><option value="tomorrow-night-blue">tomorrow-night-blue</option><option value="tomorrow-night-bright">tomorrow-night-bright</option><option value="tomorrow-night-eighties">tomorrow-night-eighties</option><option value="vs">vs</option><option value="vs2015">vs2015</option><option value="xcode">xcode</option><option value="xt256">xt256</option><option value="zenburn">zenburn</option></select></div>
</div>
<div id="display_area">
<div id="fileWindow"></div>
<textarea id="editor" spellcheck="false"></textarea>
<div id="drag_indicate"></div>
<div id="editor_render">
<div id="render_output_id">
<div id="output_wrapper_id">
<pre><code>private void initView() {
        tvFlow = findViewById(R.id.tv_flow);
        tvFlow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                flowPopWindow = new FlowPopWindow(MainActivity.this, dictList);
                flowPopWindow.showAsDropDown(tvFlow);
                flowPopWindow.setOnConfirmClickListener(new FlowPopWindow.OnConfirmClickListener() {
                    @Override
                    public void onConfirmClick() {
                        StringBuilder sb = new StringBuilder();
                        for (FiltrateBean fb : dictList) {
                            List<FiltrateBean.Children> cdList = fb.getChildren();
                            for (int x = 0; x < cdList.size(); x++) {
                                FiltrateBean.Children children = cdList.get(x);
                                if (children.isSelected())
                                    sb.append(fb.getTypeName() + ":" + children.getValue() + ";");
                            }
                        }
                        if (!TextUtils.isEmpty(sb.toString()))
                            Toast.makeText(MainActivity.this, sb.toString(), Toast.LENGTH_LONG).show();
                    }
                });

            }
        });

    }


     /**
     * 添加筛选框的数据
     */
    private void initParam() {
        String[] sexs = {"本地", "在线"};
        String[] colors = {"新建", "原有", "改造"};
        String[] company = {"交流20kv", "交流10kv", "交流5kv"};

        FiltrateBean fb1 = new FiltrateBean();
        fb1.setTypeName("获取方式");
        List<FiltrateBean.Children> childrenList = new ArrayList<>();
        for (String sex : sexs) {
            FiltrateBean.Children cd = new FiltrateBean.Children();
            cd.setValue(sex);
            childrenList.add(cd);
        }
        fb1.setChildren(childrenList);

        FiltrateBean fb2 = new FiltrateBean();
        fb2.setTypeName("建设类型");
        List<FiltrateBean.Children> childrenList2 = new ArrayList<>();
        for (String color : colors) {
            FiltrateBean.Children cd = new FiltrateBean.Children();
            cd.setValue(color);
            childrenList2.add(cd);
        }
        fb2.setChildren(childrenList2);

        FiltrateBean fb3 = new FiltrateBean();
        fb3.setTypeName("电压等级");
        List<FiltrateBean.Children> childrenList3 = new ArrayList<>();
        for (String aCompany : company) {
            FiltrateBean.Children cd = new FiltrateBean.Children();
            cd.setValue(aCompany);
            childrenList3.add(cd);
        }
        fb3.setChildren(childrenList3);

        dictList.add(fb1);
        dictList.add(fb2);
        dictList.add(fb3);
    }
</code></pre>
</div>
</div>
</div>
<div id="cssSetting">
<div id="cssToolHead">
<div id="css_select"><label></label><select><option value="最爱样式">最爱样式</option><option value="默认样式">默认样式</option><option value="标题颜色">标题颜色</option><option value="标题居中">标题居中</option><option value="标题背景">标题背景</option><option value="标题酷酷">标题酷酷</option><option value="感想,诗词">感想,诗词</option><option value="引用块样式">引用块样式</option><option value="代码块样式">代码块样式</option><option value="标题淡雅">标题淡雅</option><option value="标题前修饰">标题前修饰</option><option selected="selected" value="标题背景渐变">标题背景渐变</option><option value="字距偏大">字距偏大</option><option value="标题下边框">标题下边框</option><option value="标题上下边框">标题上下边框</option><option value="标题四边框">标题四边框</option><option value="标题首字突出">标题首字突出</option><option value="标题后修饰">标题后修饰</option><option value="标题倒挂">标题倒挂</option><option value="网格背景">网格背景</option><option value="综合示例">综合示例</option></select></div>
<label id="cssnote"></label></div>
<div id="cssEditArea"></div>
<div id="cssToolFoot"></div>
</div>
</div>
<pre>

需要调用到一些类和自定义控件,我写在GitHub上了。可以进去复制上直接使用。。

转载请注明:Android开发中文站 » 安卓实现类似京东淘宝的筛选功能,全网最简单方便

您必须 登录 才能发表评论!