当我在活动上按下一个按钮时,我的DialogFragment类被调用。我希望通过这个DialogFragment设置的日期显示在按钮文本上。FindViewById无法被该类识别。
我发现了一个类似的问题,但我无法将其与我的情况联系起来。
代码:
Button which calls the Dialogue fragment:
public void datepicker(View v) { DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getFragmentManager(), "datePicker"); }
Code for dialogue fragment:
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { @Override public Dialog onCreateDialog(Bundle savedInstanceSateate) { 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) { // Do something with the date chosen } } }