Coder Social home page Coder Social logo

optionselector's Introduction

OptionSelector

  • 自由深度的多级联动选择器(层数过深需要自行把字体改小)

运行效果图

image

实现原理

  • 一层一层地把view添加到LinearLayout中
  • Tab栏实际上是LinearLayout中添加TextView,每个Tab本质上就是一个TextView
  • Tab底部滑动的指示横线,实际上也是一个LinearLayout,添加一个滑动的动画效果
  • 最后一部分就是我们所熟悉的RecyclerView

使用

// 选择器设置
selector = contentView.findViewById(R.id.select_view);
selector.setTabAmount(array.length);
// 默认先添加第一组数据
selector.setListData(array[0]);
// tab点击更换数据
selector.setOnTabSelectedListener(new OnTabSelectedListener() {
    @Override
    public void onTabSelected(OptionSelector optionSelector, Tab tab) {
        optionSelector.setListData(array[tab.getIndex()]);
    }

    @Override
    public void onTabReselected(OptionSelector optionSelector, Tab tab) {
        optionSelector.setListData(array[tab.getIndex()]);
    }
});
selector.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void itemClick(OptionSelector selector, OptionInterface option, int tabPosition) {
        // 设置下一项的列表数据
        if (tabPosition < array.length - 1) {
            selector.setListData(array[tabPosition + 1]);
        }
    }
});

结果获取提供setOnConfirmListener的监听,确认按钮的onConfirm回调方法中提供一个结果列表,记录已选的子项。

optionselector's People

Contributors

leerogg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.