アクティビティのボタンを押すと、DialogFragment クラスが呼び出されます。このDialogFragmentで設定した日付をボタンのテキストに表示したい。FindViewById は、クラスによる認識を拒否します。
同様の質問を見つけましたが、それを私のケースに関連付けることができません。
コード:
Dialogue フラグメントを呼び出すボタン:
public void datepicker(View v) { DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getFragmentManager(), "datePicker"); }
ダイアログフラグメントのコード:
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 } } }