Android DatePicker 显示问题 可分别隐藏年、月或日

DatePickerDialog用法及只显示年月隐藏日 在代码中用法: private void showDatePicker() { //获取当前日期 Calendar calendar = Calendar.getInstance(); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH); day = calendar.get(Cale... 阅读详情

 可分别隐藏DatePicker中年、月、日:

			final DatePicker datePicker = (DatePicker) onTouchView
					.findViewById(R.id.date_picker);
			if (datePicker != null) {
				try {
					Field f[] = datePicker.getClass().getDeclaredFields();
					 //隐藏年份
					 for (Field field : f) {
					 if (field.getName().equals("mYearPicker")
					 || field.getName().equals("mYearSpinner")) {
					 field.setAccessible(true);
					 Object yearPicker = new Object();
					 yearPicker = field.get(datePicker);
					 ((View) yearPicker).setVisibility(View.GONE);
					 }
					 }
					// 隐藏月份
					 for (Field field : f) {
					 if (field.getName().equals("mMonthPicker")
					 || field.getName().equals("mMonthSpinner")) {
					 field.setAccessible(true);
					 Object monthPicker = new Object();
					 monthPicker = field.get(datePicker);
					 ((View) monthPicker).setVisibility(View.GONE);
					 }
					 }
					 //隐藏日
					 for (Field field : f) {
					 if (field.getName().equals("mDayPicker")
					 || field.getName().equals("mDaySpinner")) {
					 field.setAccessible(true);
					 Object dayPicker = new Object();
					 dayPicker = field.get(datePicker);
					 ((View) dayPicker).setVisibility(View.GONE);
					 }
					 }
				} catch (SecurityException e) {
					Log.e("ERROR", e.getMessage());
				} catch (IllegalArgumentException e) {
					Log.e("ERROR", e.getMessage());
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}





例如要隐藏年份,只需加入以下代码:

// 隐藏年份
					for (Field field : f) {
						if (field.getName().equals("mYearPicker")
								|| field.getName().equals("mYearSpinner")) {
							field.setAccessible(true);
							Object yearPicker = new Object();
							yearPicker = field.get(datePicker);
							((View) yearPicker).setVisibility(View.GONE);
						}
			



还有一种方式,不过与日期显示格式有关,故不推荐使用,方法如下:

	 ((LinearLayout) ((ViewGroup)
	 datePicker.getChildAt(0)).getChildAt(0)).getChildAt(0).setVisibility(View.GONE);
	 //0 0 0 月日
	 //0 0 1 年日
	 //0 0 2 年月



Android DatePickerDialog 只显示年月 Android DatePickerDialog 只显示年月 今天写一个日期控件,默认显示年月日,但是我现在只想显示年月,在网上找了一个比较简单容易了理解的方法,分享如下: 先看一个效果图: 处理前:  处理后: 实现的代码:     1. 通过遍历方法查找DatePicker里的子控件:年、月、日 private DatePicker find 阅读详情

相关推荐

Android中DatePicker只显示年月

Android中DatePicker只显示年月 ,点击选中后,显示在文本中

android日期选择器隐藏年,android – 从日期选择器隐藏日期

在Brain Storming半天之后我发现了这个解决方案,这可能有助于其他人有这样的场景我的日期选择器的自定义类是以下,每次用户更改月/年时,它将更新标题中的日期class CustomDatePickerDialog extends DatePickerDialog implements OnDateChangedListener {private DatePickerDialog mDate...

weixin_36285392的博客 340

手把手教你搭建硬件在回路(HIL)仿真系统:从Simulink建模到实时测试

本文详细介绍了如何从零开始搭建硬件在回路(HIL)仿真系统,涵盖Simulink建模、实时仿真、代码生成及调试等关键步骤。通过具体配置示例和优化技巧,帮助开发者解决复杂控制系统验证中的技术难题,提升半实物仿真的效率和可靠性。

weixin_30952535的博客 445

Android 通过反射来隐藏年月日的日-DatePicker

经常会有这样的需求,就是去隐藏年月日中的年或者日,下面我通过反射来达到这样的目的 /** * @param picker 传入一个DatePicker对象,隐藏或者显示相应的时间项 */ public static void hidePicker(DatePicker picker) { // 利用java反射技术得到picker内部的属性,并

tiangaopan的博客 1711

广告推荐算法 - 学习笔记(持续更新中)

本篇博客,是我用来记录学习广告推荐算法的一些笔记和总结。王喆:"深度"学习计算广告计算广告系统的核心目标是通过数据、算法和技术,在合适的场景下,将最相关的广告精准推送给目标用户,同时实现广告主媒体平台和用户之间的多方利益最大化。广告主:需求方核心目标:通过精准投放广告,最大化转化(如点击、购买)并控制成本,提升投资回报率(ROI)。关键行为:广告创建,定向设置,预算与出价策略,效果监控媒体平台:供给方核心目标:最大化广告收入,同时保持用户体验以避免用户流失。

qq_39748832的博客 2196

强化学习入门8—深入理解DDPG

本文是强化学习入门系列的第八篇,前面我们讲Actor-Critic时提到了DDPG。DDPG是google DeepMind团队提出的一种用于输出确定性动作的算法,它解决了Actor-Critic 神经网络每次参数更新前后都存在相关性,导致神经网络只能片面的看待问题这一缺点。同时也解决了DQN不能用于连续性动作的缺点。

小菜羊的博客 4314

android 展示星期方式,Android中通过日期判断星期

在自己操作DatePicker时想到了一些东西,通过实践,解决了问题,在这里和大家分享下。问题1:对于DatePicker里面的数据显示取系统当前日期问题2:用户选择日期后,在得到日期的同时获得用户所选日期是星期几首先要给大家介绍一个算法(根据日期计算星期几)如何计算某一天是星期几?—— 蔡勒(Zeller)公式历史上的某一天是星期几?未来的某一天是星期几?关于这个问题,有很多计算公式(两个通用计...

weixin_42310558的博客 612

KEPServer EX6的Modbus、MQTT和REST Server一站式配置整理说明

KEPServer EX6的Modbus、MQTT和REST Server一站式配置整理说明

syqenter的专栏 8961

android calendarview 单月显示博客,安卓——CalendarView 无法显示日期

对,最近又开始学习安卓了,毕竟有想做的app。今天在使用CalendarView 这个组件时,遇到了一个麻烦,就是只显示年份及月份,但是日期完全不显示!!!我自以为是按照书上的代码来的肯定没错,总觉得肯定又是bug。呵呵,结果居然就是因为改了一行代码又浪费了一个多小时。没改之前是这样的代码:xmlns:android="http://schemas.android.com/apk/res/andr...

weixin_29255731的博客 262

DRAM知识整理系列(三):部分时序参数整理

一、tCL-tRCD-tRP-tRAS(第一时序) 内存是根据行和列寻址的,当请求触发后,最初是tRAS(Active to precharge Delay),预充电后,内存才真正开始初始化RAS(Row Address Strobe)。一旦tRAS激活后,RAS开始进行需要数据的寻址。首先是行地址,然后初始化tRCD(RAS to CAS Delay),周期结束,接着通过CAS(Column Address Strobe)访问所需数据的十六进制地址。其中,从CAS开始到CAS结束,就是CAS延迟(即t

不吃鱼的猫的博客 7万+

时序基础模型Timer-S1:十亿参数如何革新时间序列预测

时间序列预测是数据分析与机器学习中的核心任务,旨在基于历史数据预测未来趋势。其原理在于捕捉数据中的趋势、周期性和季节性等时序依赖关系。这项技术的价值在于赋能业务决策,广泛应用于金融风控、能源管理、物联网监控和供应链优化等关键场景。传统方法依赖针对特定任务的专用模型,面临泛化能力弱和开发成本高的挑战。本文聚焦的时序基础模型,通过在海量跨领域数据上进行预训练,学习时序通用模式,并结合十亿级参数带来的强大容量,实现了性能的显著突破。这种范式转变,使得模型能够像“全科医生”一样,通过少量数据微调即可快速适应新任务,

weixin_29164843的博客 268

Android-使用DatePicker选择时间和日期(时间选择器)

Android-使用DatePicker选择时间和日期(年 月 日嵌套在DatePickerView中) 在安卓App里面,选择时间日期也是很常见的,比如在大部分APP里面填写个人信息的时候,会让你选择 你的出生日期,所以在项目中用到性好大: 注: 效果图  (注弹出弹出的方式,由底部向上弹出,消失 由上到底部)  本人写了两篇时间选择器  这篇不适合您的需求,来看看这里  链接   ...

weixin_37536584的博客 3万+

遥感图像小白--2--图像分割

遥感图像分割基础入门

Mary的博客 4233

DatePicker只显示月日,不显示年

datepicker控件中内置了三个NumberPicker控件,找到显示日的控件,然后将其隐藏掉。 在2.2系统中DatePicker控件保含了一个LinearLayout子view,而LinearLayout中包含三个NumberPicker控件分别用来显示年月日,NumberPicker控件中又包含了三个子view,分别是NumberPickerButton("+"号)\EditText\

fuzhongbin的博客 8239

人工智能智能体研究综述:从理论架构到前沿应用

AI Agent,即人工智能智能体,是指能够在特定环境中自主感知、推理、决策并执行行动以实现特定目标的智能系统[1]。自主性反应性主动性(Pro-activeness)和社会性fill:#333;important;important;fill:none;color:#333;color:#333;important;fill:none;fill:#333;height:1em;AI Agent核心特征自主性 Autonomy反应性 Reactivity主动性 Pro-activeness。

nmdbbzcl的博客 902

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

日期控件DatePicker只显示年月不显示日

有两种方式可以达到此目的: 一、在xml布局中定义datepicker控件时,设置width小一些,只够显示年月,不够显示日。 二、datepicker控件中内置了三个NumberPicker控件,找到显示日的控件,然后将其隐藏掉 代码如下: 日期控件直接设置 DatePicker dp =this.findViewById(R.id.dp);   if (dp != null

tangyunxiang的专栏 5700

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

DatePicker隐藏年、月、日

datePicker = (DatePicker) inflate.findViewById(R.id.datepicker2); 1、隐藏年 ((ViewGroup) (((ViewGroup) datePicker .getChildAt(0)).getChildAt(0))) .getChildAt(0).setVisibility(View.GONE);*/

aptx14的博客 1478

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[Android]只显示月和日的DatePickerDialog

本文转载自:http://www.cnblogs.com/over140/archive/2011/09/20/2181532.html 作者:over140 转载请注明该声明。 前言 需求要只显示月和日的日历控件,又不想自定义控件,最简单的办法就是隐藏显示年的这个框了,但DatePickerDialog并没有直接提供方法来操作,这里分享一个笨办法:) 声明   欢迎转载...

zhengxiuchen86的博客 350

【安卓开发】Android中日期选择器DatePicker和TimePicker的使用

Android用DatePicker和TimePicker实现日期选择器,包括下拉列表样式,只显示年月

我们都有光明的未来 2560

Android最简单方式实现DatePickerDialog只显示年、月、日

项目刚好有这个需求,上网查了下。有个例子还比较简单。自定义实现DatePickerDialog,然后通过反射机制隐藏里面的控件。不过这还不是最方便的,毕竟还要不同的控件代码,XML代码。直接拿到核心代码,简单丰富一下。直接调用就可以隐藏日,月选择了。 调用代码: dateDialog = new DatePickerDialog(getActivity(), listener, year, monthOfYear, dayOfMonth) {

qq_40948137的博客 1112

Android --------- DatePicker 只显示年月

效果展示 activity.xml <DatePicker android:id="@+id/datePickerStart" android:layout_marginTop="500dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:calendarViewShown="false" android:datePickerMode="

qq_42795723的博客 697

android datepicker 不显示日历,Android DatePicker遇到的那些坑

前言最近遇到一个项目,需要用到时间选择器,之前图简单,直接沿用了同事的wheelView,把可选的时间以列表的形式加载到wheelView,实现xxxx年xx月是不成问题的, 但是当我们要选择xxxx年xx月xx日时就麻烦了,月有大小月之分,年有平年闰年之分,对于每月有几天的计算还是麻烦的,所以决定弃用wheelView,用Android自带的DatePicker,在选择日期上简单方便。接下来,进...

weixin_39995280的博客 1206

DatePicker隐藏年月日显示

以前一直都是用系统提供的日期选择控件,然后开发项目需要需要隐藏年月日等不同的组合。然后就从网上找了些Demo用,项目完成之后测试人员选择系统不同的年月日显示方式引起年月日显示的错位,卧槽!后来随之了解5.0以下的和以上的执行方式也不一样 ,只得改了,改完赶紧记录一下。 TimeDialog public class TimeDialog extends Dialog { priv

LostFine的专栏 2021

Android安卓隐藏DatePickerDialog的年和日

/** * 隐藏 DatePicker的年和日 * * @param dialog */ private void hidYearDay(Dialog dialog) { int SDKVersion; try { SDKVersion = Integer.valueOf(android.os.Build.VERSION.SDK); } catch (Numb

icewst的专栏 3995

android timepicker分割线颜色,关于Android的TimePicker和DatePicker一些简单的使用问题

前几天有个需求需要实现这样的一个时间选择器。我没有用“基友”网站上的WheelView 我直接用的是Android系统提供的组件TimePicker和DatePicker.需求图如下:end.pngandroid:id="@+id/DatePicker"android:layout_width="wrap_content"android:layout_height="wrap_content" /...

weixin_35701203的博客 488

只显示年月的DatePicker

转载请注明出处:http://renyuan-1991.iteye.com/blogs/2304484 先看一下效果图: [img]http://dl2.iteye.com/upload/attachment/0117/9987/da23e737-b453-3ebf-9eb8-6af958570b1a.png[/img] 1.不显示天数的DatePicker 2.设置DatePicker的...

卒 車 480
上一篇: Android 控件显示与隐藏
下一篇: Android Dialog 点击弹出框外部 弹出框消失的问题
KeenSpace
博客等级 码龄12年 4粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值