[英]extract date Datepicker Android
I've been trying to extract the date that I get with the Datepicker
as it says here The problem comes when I try to use a function that I've created (getDate), I can't call the method from the activity
in order to obtain the string, because these method can't be resolved. 我一直在尝试使用
Datepicker
提取我在这里得到的Datepicker
因为它说的是这里的问题,当我尝试使用自己创建的函数(getDate)时,无法按顺序从activity
中调用该方法获取字符串,因为无法解析这些方法。 Can anyone explain me why? 谁能解释我为什么?
This is the code for the Datepicker
that I have in my activity. 这是我在活动中使用的
Datepicker
的代码。
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
private String date;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
date=Integer.toString(year)+"-"+Integer.toString(month)+"-"+Integer.toString(day);
}
public String getDate(){
return date;
}
}
public void showDatePickerDialog(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
String date = newFragment.getDate();
}
Finally, I found a possible solution on this post Android - Date Picker - Obatin Value ,specially this comment: 最后,我在此帖子Android-Date Picker-Obatin Value上找到了一个可能的解决方案,特别是此注释:
declare Textview as public & static & call it on dateSet method by-className.textviewName.setText();
But I still don't understand the reason why I can't do what I initially wanted 但是我仍然不明白为什么我不能做到我最初想要的原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.