0
每當onDataSet將DialogFragment調用到名爲FromToDateFragment.java的容器片段時,我想獲取日期。 FromDatePicker.java的代碼:如何從DialogFragment獲取日期每當onDateSet方法調用到容器片段
String keyDate;
@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) {
keyDate = String.valueOf(new StringBuilder().append(day).append("/").append(month+1).append("/").append(year));
}
}
在上述類調用並設置KEYDATE變量的值的方法onDateSet每當日期由用戶設定。現在我想把這個日期放到名字爲FromToDateFragment.java的容器片段中。
FromToDateFragment.java
public class FromToDateFragment extends Fragment implements View.OnClickListener{
String keyFromDate, keyToDate = null;
// getFromToDateFromFromToDateFragment getDate;
SessionManager sessionManager;
TextView fromDateTextView;
TextView toDateTextView;
String fromDate, toDate;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.from_to_date_fragment, container, false);
}
@Override
public void onClick(View view) {
int id = view.getId();
FragmentManager manager = getFragmentManager();
switch (id) {
case R.id.from_date:
DialogFragment from = new FromDatePicker();
from.show(manager, "fromDatePicker");
break;
case R.id.to_date:
DialogFragment to = new ToDatePicker();
to.show(manager, "toDatePicker");
break;
}
}
在這個片段,我只是這個代碼顯示此diaglogFragment
DialogFragment from = new FromDatePicker();
from.show(manager, "fromDatePicker");
當點擊一個按鈕。請告訴我如何在FromToDateFragment.java類中獲取日期。