0
DatePickerFragment
から選択した日付を取得するにはどうすればよいですか? OnDateSetListenerから日付に日付を取得する方法
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
int Year,Month,Day;
@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);
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
}
私の私は日付を取得し、テキストフィールドに設定したい
Fragment
:あなたは本当にただ、このようなあなたのonClickListenerを変更、DataPickerを取得するために最初のクラスを必要としない
public class CalculatorHomeFragment extends Fragment
LinearLayout lyDate;
TextView lblDate;
int Year,Month,Day;
private static CalculatorHomeFragment instance = null;
public CalculatorHomeFragment() {
}
public static CalculatorHomeFragment getInstance() {
if (instance == null)
instance = new CalculatorHomeFragment();
return instance;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_calculator_home, container, false);
lyDate = (LinearLayout) rootView.findViewById(R.id.lyDate);
lblDate = (TextView) rootView.findViewById(R.id.lblDate);
lyDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getActivity().getFragmentManager(), "datePicker");
}
});
return rootView;
}
私はDatePickerFragmentのonDateSetメソッドで日付を取得していますが、私はCalculatorHomeFragmentであるメインフラグメントに入れたいです。 –
アクティビティとフラグメントの間の通信を追加して値を更新する必要があります。 – sumandas