尝试膨胀AlertDialog.Builder
。我试图让日期轮(Yuri Kanivets的轮子)出现在我的对话框中。由于我需要的确切代码存在于他的一个类中,我只是试图实例化他的DateActivity
类(我已经导入到我的项目中)的一个新实例,然后将其添加到我的对话框中。不幸的是,我似乎无法将我的DateActivity
对象与我的对话框连接起来。我认为这将是我夸大观点的论据之一,但是这会导致崩溃。这是我的代码:尝试使用AlertDialog.Builder的类时发生空指针错误
编辑:澄清,在下面的代码中没有错误。我提到的问题是,我的DateActivity
变量与AlertDialog.Builder
没有用法,因此也没有连接。我已经尝试使用该变量(dateWheelSelector)作为builderView的参数,也尝试使用builder变量实例化,但是这两个都崩溃了。我需要弄清楚如何连接这些,因为现在我的对话框是空的。
private void setStartDate() {
//somehow I need to use this variable, but where???
DateActivity dateWheelSelector = new DateActivity();
LayoutInflater inflater = LayoutInflater.from(this);
View builderView = inflater.inflate(R.layout.wheel_date_layout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(builderView);
alert = builder.create();
/* Set the title of this dialog programatically */
TextView title = (TextView) builderView.findViewById(R.id.date_title);
title.setText("Choose Start Date");
alert.show();
}
感谢您的任何建议。
该片段看起来不错。发布logcat错误 – Blackbelt
对不起,我不清楚。看到我上面的编辑。谢谢! – Alex
你有没有NPE? – Blackbelt