使用work manager设置特定日期和时间的通知

7d7tgy0s  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(197)

我想和工作经理确定具体的日期和时间。我有edittext变量,时间选择器,时间选择器在我的项目上怎么能ı 与工作经理一起设定通知的具体日期和时间。你能快点吗
主活动类

public class mainactivity extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener {
    Calendar now = Calendar.getInstance();
    Button hatirlaticitarihsaat,backhome;
    EditText editisim,editaciklama;
    TimePickerDialog tpd;
    DatePickerDialog dpd;

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

        editisim=findViewById(R.id.hatbaslik);     
        editaciklama=findViewById(R.id.hataciklama);
        hatirlaticitarihsaat= findViewById(R.id.taarihsaatbutton);
        hatirlaticitarihsaat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DialogFragment datePicker = new DatePickerFragment();
                datePicker.show(getSupportFragmentManager(), "date picker");
            }
        });
    }

    public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
// It's time picker on time set and It's come after the date picker 
      }

    @Override
    public void onDateSet(DatePicker datePicker, int year, int month, int day) {
        //It's Date picker on date set 
        DialogFragment timePicker = new TimePickerFragment();
        timePicker.show(getSupportFragmentManager(), "time picker");

    }
}

timepickerfragment.java文件

public class TimePickerFragment extends DialogFragment {

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        return new TimePickerDialog(getActivity(), (TimePickerDialog.OnTimeSetListener) getActivity(), hour,minute, android.text.format.DateFormat.is24HourFormat(getActivity()));
    }
}

datepickerfragment.java文件

public class DatePickerFragment extends DialogFragment {
    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        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(), (DatePickerDialog.OnDateSetListener) getActivity(),year ,month,day);
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题