我在尝试在对话框中创建微调器时收到NullPointerException,并且由于代码看起来不稳定而无法调试它。不知道其他人是否有任何想法。任何帮助是极大的赞赏。在自定义对话框中设置微调器
protected Dialog onCreateDialog(int id)
{
Dialog dialog;
switch(id) {
case DIALOG_SEND_PM:
Spinner spinner = (Spinner)findViewById(R.id.pm_server);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.server_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
dialog = new Dialog(PM.this);
dialog.setContentView(R.layout.send_pm_dialog);
dialog.setTitle(R.string.send_pm);
pmMessage = (EditText) dialog.findViewById(R.id.send_pm_box);
Button sendPm = (Button) dialog.findViewById(R.id.send_pm_button);
sendPm.setOnClickListener(PM.this);
break;
default:
dialog = null;
}
我得到adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)除外;我将上下文更改为MyClass.this,异常移到下一行,这使我感到困惑。我想知道它是否具有空值的适配器,但我以前所有方式调用所有方法,而不是在对话框中调用。
相关的XML数据:
<LinearLayout>
<TextView/>
<LinearLayout>
<TextView/>
<EditText/>
<TextView/>
<Spinner
android:id="@+id/pm_server"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:background="@drawable/yblueborder"
android:textColor="#ABABAB"/>
</LinearLayout>
<Button/>
</LinearLayout>
编辑出的数据的其余部分,以便它不会占用太多的空间。
在您的活动布局或对话框的布局中是否定义了您的微调器? – Brian 2010-09-09 04:23:37
在对话框的布局中定义。我会发布这个XML。 – 2010-09-09 06:49:25