从日期选择器获得在日历上标记的价值

时间:2017-10-26 03:42:45

标签: android date datepicker calendar

从日期选择器获取值,然后在意图日历

上设置

这是我的代码,需要你的帮助:)

public Dialog onCreateDialog(Bundle savedInstanceState) {

   final Calendar c = Calendar.getInstance();
   public int year  = c.get(Calendar.YEAR);
   public int month = c.get(Calendar.MONTH);
   public int day   = c.get(Calendar.DAY_OF_MONTH);   
   return new DatePickerDialog(getActivity(), this, year, month, day);
    }

}
 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bTnCalander.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CallCalender();
        }
    });
}

public void showDatePickerDialog(View v) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getSupportFragmentManager(), "datePicker");
}

  private void CallCalender() {
    ContentValues values = new ContentValues();
    Calendar cal = Calendar.getInstance();
    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("minutes", METHOD_ALARM);
    intent.putExtra("allDay", false);enter code here
    startActivity(intent);

}

我正面临一个问题,我如何从日期选择器中获取价值,而不是之前的那个值,然后将在Intent Calender上标记。

1 个答案:

答案 0 :(得分:0)

致电时,

return new DatePickerDialog(getActivity(), this, year, month, day);

您需要指定放置OnDateSetListener的{​​{1}},这是我为您制作的示例,

this