DatePickerDialog并没有改变我选择的日期

时间:2016-03-11 12:01:43

标签: android

DatePickerDialog并未改变我选择的日期

    AlertDialog.Builder alert = new AlertDialog.Builder(TodoListManagerActivity.this);
    alert.setCancelable(true);
    alert.setTitle("Add New Item");
    LayoutInflater factory = LayoutInflater.from(this);
    final View a = factory.inflate(R.layout.dialoglay, null);
    alert.setView(a);
    final EditText text = (EditText) a.findViewById(R.id.userchoice);
    Button chooseDate = (Button) a.findViewById(R.id.dateButton);

    final Calendar calendar = Calendar.getInstance();
    final DatePickerDialog.OnDateSetListener[] listener = {null};
    final int[] yearA = new int[2];
    final int[] monthA = new int[2];
    final int[] dayA = new int[2];
    yearA[0] = calendar.get(Calendar.YEAR);
    monthA[0] = calendar.get(Calendar.MONTH);
    dayA[0] = calendar.get(Calendar.DAY_OF_MONTH);

    chooseDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new DatePickerDialog(TodoListManagerActivity.this, listener[0], yearA[0], monthA[0], dayA[0]).show();

            listener[0] = new DatePickerDialog.OnDateSetListener() {


                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Log.d("here2", "ggg");
                    yearA[0] = year;
                    monthA[0] = monthOfYear + 1;
                    dayA[0] = dayOfMonth;

                }
            };
        }
    });**strong text**

2 个答案:

答案 0 :(得分:1)

使用此代码。

final int mYear,mMonth,mDay;

    // Launch Date Picker Dialog

    final Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog dpd = new DatePickerDialog(this,
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                mYear=year;
                mMonth=monthOfYear+1;
                mDay=dayOfMonth;

                }

            }, mDay, mMonth, mYear);
        dpd.getDatePicker().setMinDate(c.getTimeInMillis());
        dpd.show();

答案 1 :(得分:0)

将您的监听器放在显示代码行的对话框上方。

Measure:=CALCULATE(sum([value]),filter(Table1,FIND("SP11",Table1[string],1,0)>0))