简体   繁体   English

如何在我的号码选择器索引中设置当前月和年?

[英]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.

相关问题 如何从当前月份和年份的日期选择器显示以限制显示上一年和月份的android? - How to display from current month and year in date picker to restrict showing previous year and month android? 如何在文本视图中设置当前的月份名称(字符串)和年份? - how to set current month name(string) and year in a textview? 如何在 android 中打开日期选择器时设置默认年份(但在滚动年份时需要显示其他年份直到当前年份) - How to set a default year while opening the date picker in android (But while scrolling the year it needs to show other years till current year) Android上片段中的月份和年份选择器 - Month and year picker in fragment on android 如何更改 Android 材料日期选择器上的年份选择器和月份选择器 V 形的颜色? - How to change the color of Year Picker and Month picker chevron on the Android Material Date Picker? 如何仅从日期选择器获取日期的月份和年份 - How to Get date from Date Picker only month and year 如何显示仅具有月份和年份字段的Android日期选择器? - How to display date picker for android with only month and year fields? 如何设置日期选择器中特定的月份或年份? - how to set a specific month or year for slection in datepicker? 如何将日期转换为android中的年数和月数 - how to convert date to number of year in android and number of month 如何从 kotlin 中的 firebase 获取当前月份和年份数据 - How to fetching current month and year data from firebase in kotlin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM