i got the next problem. I want to pass the date i've entered using my DatePickerFragment
to TextView
, but i don't know how i can actually do it.
When i create TextView
object in DatePickerFragment
class and then set the text in it using onDateSet
method - the app crashes. Maybe this question too basic, but i didn' find any suitable solution.
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener{
TextView tvDate1 = (TextView) getView().findViewByiD(R.id.tvDate);
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
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);
return new DatePickerDialog(getActivity(),this,year,month,day);
}
public void onDateSet(DatePicker view,int year, int month, int day){
String
StringBuilder sb = new StringBuilder();
sb.append(day);
sb.append("/");
sb.append(month);
sb.append("/");
sb.append(year);
tvDate1.setText(sb);
}
}
See Question&Answers more detail:os