简体   繁体   English

Android上片段中的月份和年份选择器

[英]Month and year picker in fragment on android

For my fragment class I need month and year picker, how can i change the following date picker code into month/year picker or please share any tutorial/example that working in fragment. 对于我的片段类,我需要月份和年份选择器,如何将下面的日期选择器代码更改为月份/年份选择器,或者请共享在片段中工作的任何教程/示例。

public class Month_Year_Picker extends Fragment{

  .............
        expDate.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Calendar c = Calendar.getInstance();
                DialogFragment newFragment = new DateFragment();
                newFragment.show(getChildFragmentManager(),
                        "DatePicker");
            }
        });
...........
@SuppressLint("ValidFragment")
class DateFragment extends DialogFragment implements
        DatePickerDialog.OnDateSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Calendar calendar = Calendar.getInstance();
        int yy = calendar.get(Calendar.YEAR);
        int mm = calendar.get(Calendar.MONTH);
        int dd = calendar.get(Calendar.DAY_OF_MONTH);

        return new DatePickerDialog(getActivity(), this, yy, mm, dd);
    }   


    @Override
    public void onDateSet(DatePicker arg0, int yy, int mm, int dd) {
        // TODO Auto-generated method stub
    }

}

}

I solved using date picker like iPhone,and just hided date field so that I get Month and year picker. 我解决了使用类似iPhone的日期选择器的问题,只是隐藏了日期字段,以便获得月和年选择器。

Source: 资源:

http://sunilsuthar02.blogspot.in/2013/04/date-picker-like-iphone-in-android.html http://sunilsuthar02.blogspot.in/2013/04/date-picker-like-iphone-in-android.html

I tried using the existing DatePicker in-order to pick month and year only. 我尝试使用现有的DatePicker来仅选择月份和年份。 But its a very hacky approach and does not work well on all device. 但这是一种非常骇人听闻的方法,因此无法在所有设备上正常运行。

Went ahead making a modified Date Picker called Simple Date picker ... have used the code similar to Date Picker just to show month and year 继续进行修改后的日期选择器,称为简单日期选择器...使用了类似于日期选择器的代码来显示月份和年份

see https://github.com/resengupta/Month-Year-Date-Picker 参见https://github.com/resengupta/Month-Year-Date-Picker

SimpleDatePickerDialog.java class is responsible for showing the month and year number picker. SimpleDatePickerDialog.java类负责显示月份和年份数字选择器。 SimpleDatePickerDelegate.java works to apply rules to the number pickers. SimpleDatePickerDelegate.java可将规则应用于号码选择器。 SimpleDatePickerDialogFragment.java is a DialogFragment which wraps the alert dialog. SimpleDatePickerDialogFragment.java是一个DialogFragment,用于包装警报对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:只有月份和年份的日期选择器 - Android: Date picker with only month and the year Android只有材料设计的月份和年份选择器 - Android only month and year picker in material design 在选择年份月份或日期时,日期时间选择器会跳过项目 - Datetime picker skips items when selecting year month or day Android 仅显示android中的棒棒糖5.0的月份和年份的日期选择器 - Show date picker with month and year only for lollipop 5.0 in android 如何显示仅具有月份和年份字段的Android日期选择器? - How to display date picker for android with only month and year fields? 如何从当前月份和年份的日期选择器显示以限制显示上一年和月份的android? - How to display from current month and year in date picker to restrict showing previous year and month android? 如何更改 Android 材料日期选择器上的年份选择器和月份选择器 V 形的颜色? - How to change the color of Year Picker and Month picker chevron on the Android Material Date Picker? Android-片段中的联系人选择器 - Android - contact picker in fragment 日期选择器无法获得edittext中的月份和年份 - Date Picker not get month and year in edittext 仅限android日期选择器年份 - android date picker year only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM