showDatePickerDialog无法加载的DatePicker对话 [英] showDatePickerDialog can't load DatePicker Dialog

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

问题描述

我加载对话框用这种方法 showDatePickerDialog(this.getCurrentFocus()); 。而在此之前的罚款。但我当我把里面的 setOnClickListener 为点击按钮显示的对话框中,有编译器错误。错误是的方法getCurrentFocus()的类型是未定义的新View.OnClickListener(){} 。我的code是如下

  frombutton.setOnClickListener(新OnClickListener(){        公共无效的onClick(视图v){
            showDatePickerDialog(this.getCurrentFocus());        }
    });


解决方案

的问题是,新OnClickListener()创建一个内部类,它的类型是不是活动,就像外部类。

为此,这个 refferes到 OnClickListener ,而不是你的活动。在 getCurrentFocus() -method在监听级不存在,因此不能被发现。

要解决的办法是明确地说,你要在这个从surounding(外)类。你做到这一点之前,添加外部类的名称本

  showDatePickerDialog(YOURACTIVITYCLASSNAMEHERE.this.getCurrentFocus());

I load the dialog with this method showDatePickerDialog(this.getCurrentFocus());. That is fine before. But I when I put inside the setOnClickListener for displaying the dialog on the button click, there is compiler error. The error is The method getCurrentFocus() is undefined for the type new View.OnClickListener(){}. My code is as follow

    frombutton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            showDatePickerDialog(this.getCurrentFocus());

        }
    });

解决方案

The problem is, that new OnClickListener() creates an inner class, which is not of type Activity, like the outer class.

Therefor, this refferes to the OnClickListener, not your activity. The getCurrentFocus()-method does not exist in the listener-class and can therefore not be found.

The way to resolve that is to explicitly say that you want the this from the surounding (outer) class. You do that by adding the outer-classes name before this:

showDatePickerDialog(YOURACTIVITYCLASSNAMEHERE.this.getCurrentFocus());

这篇关于showDatePickerDialog无法加载的DatePicker对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆