本文介绍了安卓的DatePicker和DatePicker的对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个code此处的选项菜单上

I have this code here on the options menu

Dialog dialog = new Dialog(ScheduleActivity.this);
dialog.setTitle("Add Event");
dialog.setContentView(R.layout.add_even_on);
Button datePicker = (Button) dialog.findViewById(R.id.datePicker);
final DialogFragment dateFrag = new MyDatePicker();
    datePicker.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                dateFrag.show(getSupportFragmentManager(), "datePicker");               
            }
        });
dialog.show();

时,说添加事件的选项菜单上单击,会出现一个对话框,有一个按钮,显示 DatePickerDialog 和它旁边的是一个的TextView 反映选择在 DatePickerDialog 的日期,这里是我的机器人开发者得到了关于如何使用DatePickerDialog类。

when, say "Add Event" on the option menu is clicked, a Dialog appears, with a button that shows a DatePickerDialog and beside it is a TextView that reflects the date chosen in the DatePickerDialog, here is the class I got from Androids Developer on how to use the DatePickerDialog.

class MyDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener {
 int pYear;
 int pDay;
 int pMonth;

@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);
  }

  public void onDateSet(DatePicker view, int year, int month, int day) {
    pYear = year;
    pDay = day;
    pMonth = month;
  }
}

所以我的问题是,我如何得到milleseconds值当我点击设置就这反过来又自动关闭它DatePickerDialog,并返回到我的对话,其中包含了打开DatePickerDialog和一个TextView反映按钮watever日期选择了DatePickerDialog ......我不会表现出一个我选择了DatePickerDialog ...

So my problem is that how do i get the Value in milleseconds when i click "Set" on the DatePickerDialog which in turn automatically closes it, and returns to my Dialog which contains the button which open the DatePickerDialog and a Textview which reflects watever date is chosen the DatePickerDialog... i wont show the one i chose inside the DatePickerDialog...

下面是我的意思的图片,

Here is a picture of what i mean,

所以,当我点击看到的下一张图片一个DatePickerDialog框出现在匹克日期按钮

So when i click on the Pick Date Button a DatePickerDialog box appears as seen on the next picture

当我点击设置,我想考虑到从DatePickerDialog

and when i click set, i wanted to take into account the value in millseconds from that DatePickerDialog

推荐答案

下面我提供一些code希望它可以帮助你。

Here I Provide Some Code Hope It Helps You..

public class NewReminder extends Activity {
private static final int DATE_DIALOG_ID = 1;
private int year;
private int month;
private int day;
EditText editTextDate;
private String currentDate;
private Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addnewreminder);
    initialize();
    context = getApplicationContext();
    OnClickListener listenerDate = new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            final Calendar c = Calendar.getInstance();
            year = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day = c.get(Calendar.DAY_OF_MONTH);
            showDialog(DATE_DIALOG_ID);
        }
    };
    editTextDate.setOnClickListener(listenerDate);

}

private void initialize() {
    // TODO Auto-generated method stub

    editTextDate = (EditText) findViewById(R.id.editTextDate);

}


private void updateDisplay() {
    currentDate = new StringBuilder().append(day).append(".")
            .append(month + 1).append(".").append(year).toString();

    Log.i("DATE", currentDate);
}

OnDateSetListener myDateSetListener = new OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker datePicker, int i, int j, int k) {

        year = i;
        month = j;
        day = k;
        updateDisplay();
        editTextDate.setText(currentDate);
    }
};



@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, myDateSetListener, year, month,
                day);
    }
    return null;
}
}

这篇关于安卓的DatePicker和DatePicker的对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:41