我正在为多个片段使用datepicker的自定义类。它工作正常,但在一个片段中,我想通过日期选择器显示Dialog Fragment中的年份。
自定义DatePicker类
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
Calendar calendar = Calendar.getInstance();
public static final String TAG="###Date Selector###";
String name;
String To,From;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"ON CREATE CALLING ");
}
@Override
public void onStart() {
super.onStart();
Log.d(TAG,"ON START CALLING ");
Log.d(TAG,"Fragment Is Calling By "+name+" "+To+" "+From);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Log.d(TAG,"On Create Dialog Calling");
name=getArguments().getString("Calling");
To=getArguments().getString("To");
From=getArguments().getString("From");
if (name.equals("###EDIT PROFILE###")) {
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);
} else if (name.equals("====Add PPL====")) {
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,00);
}
return null;
}
public void onDateSet(DatePicker view, int yy, int mm, int dd) {
populateSetDate(yy, mm+1, dd);
}
public void populateSetDate(int year, int month, int day) {
TextView dob=null;
if (name.equals("###EDIT PROFILE###")){
dob= (TextView) getActivity().findViewById(R.id.edit_profile_dobTextView);
Log.d(TAG,"Calling Fragment is Edit Profile");
}
else if (name.equals("====Add PPL====")){
Log.d(TAG,"Calling Fragment is ADD PPL");
if (To!=null && !To.equals("")){
dob=(TextView) getActivity().findViewById(R.id.ppl_To_passing_year);
Log.d(TAG,"Calling Fragment is ADD PPL and inside TO");
}
else if (From!=null && !From.equals("")){
dob=(TextView) getActivity().findViewById(R.id.ppl_From_passing_year);
Log.d(TAG,"Calling Fragment is ADD PPL and inside From");
}
}
String nameOfMonth=new DateFormatSymbols().getMonths()[month-1];
dob.setText(day+" "+nameOfMonth+" "+year);
}
}
我想在对话中显示年份,有时只显示月份和年份。我必须编辑这个课程才能获得年份,月份和年份。
谢谢