DatePicker在Android中的Textview中不起作用

时间:2017-09-17 16:24:46

标签: android datepicker

我正在尝试在textview中显示datepiecker,但是textview无法正常工作。代码未显示任何错误,但在运行应用程序时,日期不会出现。这是我的datepicker代码如下所示:

  login(email: string, password: string): Observable<boolean> {
    return new Observable(observer => {
      var data = { email: email, password: password };
      this.http.post(this.server_url + '/auth/authenticate', data).subscribe(x => {
        var result = {
          email: x.json().email,
          token: x.json().token,
          roles: x.json().roles.map(x => x.name)
        }
        localStorage.setItem(this._userKey, JSON.stringify(result));
        observer.next(true);
        observer.complete();
      }, er => {
        if (er.status == 401) {
          observer.next(false);
          observer.complete();
        } else {
          console.log(er);
          observer.error(er);
          observer.complete();
        }
      });
    });
  }

我的问题是如何在textview中显示日期选择器?请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这个

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


 DatePickerDialog mDatePicker = new DatePickerDialog(SearchResultClass.this,
                                  new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {

         tv.setText(selectedyear + "-" + month + "-" + selectedday);

                    }
         }, mYear, mMonth, mDay);

  mDatePicker.getDatePicker().setMinDate(System.currentTimeMillis());

  mDatePicker.show();