Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AsyncAction在android的onDateset中执行两次_Android - Fatal编程技术网

AsyncAction在android的onDateset中执行两次

AsyncAction在android的onDateset中执行两次,android,Android,我想在设置日期时调用AsyncAction 我的目标是在设置日期时异步运行,但现在它运行两次 我写了下面的代码,但异步执行了两次 DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear,

我想在设置日期时调用AsyncAction

我的目标是在设置日期时异步运行,但现在它运行两次

我写了下面的代码,但异步执行了两次

DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                int dayOfMonth) {

           String mo = null,dmo = null;
           int month = monthOfYear+1;
           if(month<=9)
           {
               mo = "0"+ String.valueOf(month);
           }
           //int dmonth = monthOfYear+1;
           if(dayOfMonth<=9)
           {
               dmo = "0"+ String.valueOf(dayOfMonth);
           }


            new AsyncActionBalance().execute("LAST."+String.valueOf(mo.toString()+dmo.toString()), "RECHARGE REPORT", null);


        }

};

这是一个安卓错误。它发生在果冻豆上

为了克服这个问题。不要调用onDateSet listener,而要使用set-positive按钮。像这样尝试从日期选择器获取日期

 final DatePickerDialog dpDialog = new DatePickerDialog(activity, null, year, month, dayOfMonth);
        dpDialog.setButton(DatePickerDialog.BUTTON_POSITIVE, "Done", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                android.widget.DatePicker dp = dpDialog.getDatePicker();
                Log.e(TAG, "selected Date:" + dp.getYear() + " " + dp.getMonth() + "  " + dp.getDayOfMonth());
            }
        });

        dpDialog.show();

我用计数器解决了这个问题。现在我也把按钮放在负片上,我调用了dialog.discouse();之后也执行run。为什么?
 final DatePickerDialog dpDialog = new DatePickerDialog(activity, null, year, month, dayOfMonth);
        dpDialog.setButton(DatePickerDialog.BUTTON_POSITIVE, "Done", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                android.widget.DatePicker dp = dpDialog.getDatePicker();
                Log.e(TAG, "selected Date:" + dp.getYear() + " " + dp.getMonth() + "  " + dp.getDayOfMonth());
            }
        });

        dpDialog.show();