我在嘗試在對話框中創建微調器時收到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