[英]How to set Current Month and year in my number picker index?
How to can I set the current month and year in my NumberPicker
index ? 如何在NumberPicker
索引中设置当前月份和年份? I have two NumberPicker
instances - the first is for the and second is for the year. 我有两个NumberPicker
实例-第一个用于,第二个用于年份。 Both are set as string arrays, but how do I set current position as the current month? 两者都设置为字符串数组,但是如何将当前位置设置为当前月份?
Here is my current code: 这是我当前的代码:
final String wheelMenu2[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
NumberPicker numberPicker2 = (NumberPicker) findViewById(R.id.numberpicker2);
numberPicker2.setMinValue(0);
numberPicker2.setMaxValue(wheelMenu2.length-1);
numberPicker2.setWrapSelectorWheel(true);
numberPicker2.setDisplayedValues(wheelMenu2);
int posmonthwheel2 =numberPicker2.getValue();
s4 = wheelMenu2[posmonthwheel2];
SimpleDateFormat dayFormat = new SimpleDateFormat("MMM", Locale.US);
Calendar calendar = Calendar.getInstance();
String month = dayFormat.format(calendar.getTime());
month will give have the value of the current month ie, Jan, Feb, Mar etc. Use this to compare with your array and set it to the view month将给出当前月份的值,即Jan,Feb,Mar等。使用此值与您的数组进行比较并将其设置为视图
and for setting in your number formatter use the below method, 对于数字格式化程序的设置,请使用以下方法,
numberPicker.setValue(// int position value of the result); numberPicker.setValue(//结果的int位置值);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.