Android-PickerView 的使用

github > https://github.com/Bigkoo/Android-PickerView

相关文章:

Android 知识点总结(目录) https://blog.csdn.net/a136447572/article/details/81027701

Android-PickerView 的使用_第1张图片

1 implementation 'com.contrarywind:Android-PickerView:4.1.6'

2 private OptionsPickerView pvNoLinkOptions ;

3

    private ArrayList monthList = new ArrayList<>();
    private ArrayList hoursList = new ArrayList<>();
    private ArrayList fenList = new ArrayList<>();

		monthList.add("1月");
		monthList.add("1月");
		monthList.add("1月");
		monthList.add("1月");

  		hoursList.add("21点");
        hoursList.add("22点");
        hoursList.add("23点");

        fenList.add("00分");
        fenList.add("15分");
        fenList.add("30分");
        fenList.add("45分");

4

   pvNoLinkOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {

                String str = "one:" + monthList.get(options1)
                        + "\ntwo:" + hoursList.get(options2)
                        + "\nthree:" + fenList.get(options3);

                Toast.makeText(ServiceFabuActivity.this, str, Toast.LENGTH_SHORT).show();
            }
        })
                .setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
                    @Override
                    public void onOptionsSelectChanged(int options1, int options2, int options3) {
//                        String str = "options1: " + options1 + "\noptions2: " + options2 + "\noptions3: " + options3;
//                        Toast.makeText(ServiceFabuActivity.this, str, Toast.LENGTH_SHORT).show();
                    }
                })
                // .setSelectOptions(0, 1, 1)
                .setCancelColor(getResources().getColor(R.color._color_333))
                .setSubmitColor(getResources().getColor(R.color._color_333))
                .build();
        pvNoLinkOptions.setNPicker(monthList, hoursList, fenList);
        if (dayCom>0&&dayCom

5pvNoLinkOptions.show();


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.back_layout){
            finish();
        }else if (v.getId() == R.id.time_layout && pvNoLinkOptions != null) {
            pvNoLinkOptions.show();
        }
    }

6

private void getNoLinkData() {

        String [] time = getTime(new Date()).split("-");

        int day = Integer.valueOf(time[2]);
//        int month = Integer.valueOf(time[1]);
        int month = Integer.valueOf(time[1]) ;
        int length = getDayLength((month)+"");
        int lastMonth ,nextMonth ;
        if (month == 1){
            lastMonth = 12 ;
            nextMonth = 2 ;
        }else if (month == 12){
            lastMonth = 11 ;
            nextMonth = 1 ;
        }else{
            lastMonth = month-1;
            nextMonth = month+1;
        }
        int lastMonthLenght =  getDayLength(lastMonth+"");
        int nextMonthLenght =  getDayLength(nextMonth+"");
        for (int i = 1; i < lastMonthLenght+1; i++) {
            monthList.add(lastMonth+"/"+i);
        }
        for (int i = 1; i < length+1; i++) {
            monthList.add(time[1]+"/"+i);
        }
        for (int i = 1; i < nextMonthLenght+1; i++) {
            monthList.add(nextMonth+"/"+i);
        }

        dayCom = lastMonthLenght+day-1;

        hoursList.add("00点");
        hoursList.add("01点");
        hoursList.add("02点");
        hoursList.add("03点");
        hoursList.add("04点");
        hoursList.add("05点");
        hoursList.add("06点");
        hoursList.add("07点");
        hoursList.add("08点");
        hoursList.add("09点");
        hoursList.add("10点");
        hoursList.add("11点");
        hoursList.add("12点");
        hoursList.add("13点");
        hoursList.add("14点");
        hoursList.add("15点");
        hoursList.add("16点");
        hoursList.add("17点");
        hoursList.add("18点");
        hoursList.add("19点");
        hoursList.add("20点");
        hoursList.add("21点");
        hoursList.add("22点");
        hoursList.add("23点");


        fenList.add("00分");
        fenList.add("15分");
        fenList.add("30分");
        fenList.add("45分");

    }

    private int getDayLength(String month){
        if ("135781012".contains(month)||"01030507081012".contains(month)){
            return 31;
        }else if ("2".contains(month)||"02".contains(month)){
            return 28;
        }else{
            return 30;
        }
    }

你可能感兴趣的:(andriod)