Android TeaPickerView data cascade selector

Android TeaPickerView data cascade selector

Data Cascade Selector, Hierarchical Structure, Multiple Data Screening, Must Star

Github address

YangsBryant/TeaPickerView
(Github typesetting is better, it is recommended to enter here to view the details, if you think it is good, click star! )
 

import module

1

2

3

4

5

6

7

allprojects {

    repositories {

        google()

        jcenter()

        maven { url 'https://www.jitpack.io' }

    }

}

1

implementation 'com.github.YangsBryant:TeaPickerView:1.0.2'


main code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.mButton)

    Button button;

     

    List<String> mProvinceDatas=new ArrayList<>();

    Map<String, List<String>> mSecondDatas= new HashMap<>();

    Map<String, List<String>> mThirdDatas= new HashMap<>();

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        ButterKnife.bind( this );

        intiPickerView();

    }

    private  void intiPickerView(){

        //一级列表

        ProvinceBean provinceBean = new ProvinceBean();

        mProvinceDatas.addAll(provinceBean.getRepData().getProvince());

        //二级列表

        SecondBean secondBean = new SecondBean();

        mSecondDatas.putAll(secondBean.getRepData().getSecond());

        //三级列表

        ThirdBean thirdBean = new ThirdBean();

        mThirdDatas.putAll(thirdBean.getRepData().getThird());

        Log.i("json", JsonArrayUtil.toJson(mProvinceDatas));

        Log.i("json",JsonArrayUtil.toJson(mSecondDatas));

        Log.i("json",JsonArrayUtil.toJson(mThirdDatas));

        //设置数据有多少层级

        PickerData data=new PickerData();

        data.setFirstDatas(mProvinceDatas);//json: ["广东","江西"]

        data.setSecondDatas(mSecondDatas);//json: {"江西":["南昌","赣州"],"广东":["广州","深圳","佛山","东莞"]}

        data.setThirdDatas(mThirdDatas);//json: {"广州":["天河区","白云区","番禹区","花都区"],"赣州":["章贡区","黄金开发区"],"东莞":["东城","南城"],"深圳":["南山区","宝安区","龙华区"],"佛山":["禅城区","顺德区"],"南昌":["东湖区","青云谱区","青山湖区"]}

        data.setInitSelectText("请选择");

        TeaPickerView teaPickerView =new TeaPickerView(this,data);

        teaPickerView.setScreenH(3)

                .setDiscolourHook(true)

                .setRadius(25)

                .setContentLine(true)

                .setRadius(25)

                .build();

        button.setOnClickListener(v -> {

            //显示选择器

            teaPickerView.show(button);

        });

        //选择器点击事件

        teaPickerView.setOnPickerClickListener(pickerData -> {

            Toast.makeText(MainActivity.this,pickerData.getFirstText()+","+pickerData.getSecondText()+","+pickerData.getThirdText(),Toast.LENGTH_SHORT).show();

            teaPickerView.dismiss();//关闭选择器

        });

    }

}

TeaPickerView properties

method name

Attributes

setHeights(int mHeight)

Display the specific height (dp), setting 0 is adaptive (height has no default value, it needs to be set actively)
setScreenH(int num) The displayed height as a percentage of the screen
setBackground(int color) Set the overall background color to #ffffff by default
setRadius(int mRadius) Set rounded corners, default 0
setContentBackground(int color) The background color of the content bar defaults to #ffffff
setContentHeight(int mHeight) The height of the content bar (dp) defaults to 50dp
setContentText(int size,int color) The size and color of the content column font, the default is 16sp, #0aa666, this method will fix the color
setContentText(ColorStateList drawable) Customize the content bar font color changer Create a color folder in the res directory and use the selector default color #555 Select the color #0aa666
setContentLine(boolean bl) 内容栏选中是否有下划线 默认不开启
setContentLineColor(Drawable drawable) 自定义内容栏下划线用layer-list 默认是下边框描边 颜色#0fbc72 高度1dp
setLine(int mHeight,int color) 分割线的高度和颜色 默认是0.5dp #e5e5e5
setitemHeight(int mHeight) 设置list的item的高度(dp) 默认是40dp
setListText(int size,int color) 设置list的字体大小和颜色 默认是15 #555
setScrollBal(boolean bl) 设置list是否显示滚动条,默认false
setAlpha(float mFloat) 设置阴影层的透明度 默认是0.5f
setDiscolour(boolean bl) 设置选中项是否加色,默认true
setDiscolourColor(int color) 设置选中项加色的颜色值,默认#0aa666
setDiscolourHook(boolean bl) 设置选中项是否有√图标,默认false
setCustomHook(Drawable drawable) 自定义√图标
build() 参数设置完毕,一定要build一下

 设置数据

方法名 属性                  
setInitSelectText(String firstText) 初始文字
setFirstDatas(List mFirstDatas) 设置一级数据
setSecondDatas(Map<String, List> mSecondDatas) 设置二级数据
setThirdDatas(Map<String, List> mThirdDatas) 设置三级数据
setFourthDatas(Map<String, List> mFourthDatas) 设置四级数据

给出参考bean地址

Level 1 ProvinceBean  Level 2 SecondBean  Level 3 ThirdBean

Default content bar font color changer

1

2

3

4

5

6

7

8

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true" android:color="@color/picker_select_text_color"/>

    <item android:state_pressed="true" android:color="@color/picker_select_text_color"/>

    <item android:state_checked="true" android:color="@color/picker_select_text_color"/>

    <item android:state_focused="true" android:color="@color/picker_select_text_color"/>

    <item android:color="@color/picker_text_color"/>

</selector>

Default content bar underline

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 边框颜色值 -->

    <item>

        <shape>

            <solid android:color="@color/station_average" />

        </shape>

    </item>

    <item android:bottom="1dp"> <!--设置只有底部有边框-->

        <shape>

            <solid android:color="#ffffff" />

        </shape>

    </item>

</layer-list>

Reprinted in: Android TeaPickerView Data Cascading Picker - YangBryant - Blog Park

Guess you like

Origin blog.csdn.net/weixin_42602900/article/details/123355921