android 滚轮选择器

andrioid没有提供和苹果相似的时间选择器,如果想要实现我推荐
https://github.com/gzu-liyujiang/AndroidPicker
android 滚轮选择器_第1张图片

TimePicker picker = new TimePicker(ThirdActivity.this, TimePicker.HOUR_24);
picker.setUseWeight(false);
picker.setCycleDisable(false);
picker.setRangeStart(0, 0);//00:00
picker.setRangeEnd(23, 59);//23:59
int currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int currentMinute = Calendar.getInstance().get(Calendar.MINUTE);
picker.setSelectedItem(currentHour, currentMinute);
picker.setTopLineVisible(false);
picker.setTextPadding(DensitySizeUtil.dp2px(ThirdActivity.this, 15));
picker.setOnTimePickListener(new TimePicker.OnTimePickListener() {
    @Override
    public void onTimePicked(String hour, String minute) {
        Logger.d(hour + ":" + minute);
    }
});
picker.show();

final DatePicker picker = new DatePicker(ThirdActivity.this);
picker.setCycleDisable(false);
picker.setCanceledOnTouchOutside(true);
picker.setUseWeight(true);
picker.setTopPadding(DensitySizeUtil.dp2px(ThirdActivity.this, 10));
picker.setRangeEnd(2111, 1, 11);
picker.setRangeStart(2016, 8, 29);
picker.setSelectedItem(2050, 10, 14);
picker.setResetWhileWheel(false);
picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
    @Override
    public void onDatePicked(String year, String month, String day) {
        Logger.d(year + "-" + month + "-" + day);
    }
});
picker.setOnWheelListener(new DatePicker.OnWheelListener() {
    @Override
    public void onYearWheeled(int index, String year) {
        picker.setTitleText(year + "-" + picker.getSelectedMonth() + "-" + picker.getSelectedDay());
    }

    @Override
    public void onMonthWheeled(int index, String month) {
        picker.setTitleText(picker.getSelectedYear() + "-" + month + "-" + picker.getSelectedDay());
    }

    @Override
    public void onDayWheeled(int index, String day) {
        picker.setTitleText(picker.getSelectedYear() + "-" + picker.getSelectedMonth() + "-" + day);
    }
});
picker.show();
 
new AddressInitTask(ThirdActivity.this, new AddressInitTask.InitCallback() {
        @Override
        public void onDataInitFailure() {
            Logger.d("数据初始化失败");
        }
        @Override
        public void onDataInitSuccess(ArrayList provinces) {
            AddressPicker picker = new AddressPicker(ThirdActivity.this, provinces);
            picker.setCycleDisable(false);
            picker.setOnAddressPickListener(new AddressPicker.OnAddressPickListener() {
                @Override
                public void onAddressPicked(Province province, City city, County county) {
                    String provinceName = province.getName();
                    String cityName = "";
                    if (city != null) {
                        cityName = city.getName();
                        //忽略直辖市的二级名称
                        if (cityName.equals("市辖区") || cityName.equals("市") || cityName.equals("县")) {
                            cityName = "";
                        }
                    }
                    String countyName = "";
                    if (county != null) {
                        countyName = county.getName();
                    }
                    Logger.d(provinceName + " " + cityName + " " + countyName);
                }
            });
            picker.show();
        }
    }).execute();
}

你可能感兴趣的:(android 滚轮选择器)