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