You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MaterialDatePicker.Builder出现参数化类原始使用lint报错如何解决

报错原因

MaterialDatePicker.Builder 属于带泛型参数的类,你在声明变量时没有指定泛型类型,直接使用了无参数的原始类形式,因此触发了lint的泛型使用规范检查。

修复方法

在声明Builder变量时,补充和返回值匹配的泛型类型Long即可(单日期选择器的返回结果是Long类型的时间戳),修改后的完整代码如下:

// 仅修改第一行,给Builder加上泛型参数<Long>
MaterialDatePicker.Builder<Long> builder = MaterialDatePicker.Builder.datePicker();

builder.setTitleText("Select date range of publication");

// If you want to set theme here
//builder.setTheme(R.style.MaterialTheme);

MaterialDatePicker<Long> materialDatePicker = builder.build();

materialDatePicker.show(getParentFragmentManager(),"DATE_PICKER");

materialDatePicker.addOnPositiveButtonClickListener(selection -> {
    etDatesToPublish.setText(materialDatePicker.getHeaderText());
});

补充说明

如果你后续使用的是日期范围选择器,对应泛型参数要替换为Pair<Long, Long>。

内容的提问来源于stack exchange,提问作者Emmanuel Njorodongo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 02:15:02