我需要向 AlertDialog 添加一个无线电组,所以我编写了以下代码:
AlertDialog.Builder screenDialog = new AlertDialog.Builder(this);
screenDialog.setTitle("Captured Screen");
RadioGroup azione = (RadioGroup) findViewById(R.id.azione_stop);
LinearLayout dialogLayout = new LinearLayout(getApplicationContext());
dialogLayout.setOrientation(LinearLayout.VERTICAL);
dialogLayout.addView(azione);
screenDialog.setView(dialogLayout);
screenDialog.show();
这是包含 RadioGroup 的 xml:
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/azione_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/ritornare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#000000"
android:text="Ritornare" />
<RadioButton
android:id="@+id/chiudi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#
android:text="Chiudi chiamata" />
<RadioButton
android:id="@+id/offerta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Segna offerta" />
当我打开 alertdialog 时,我收到一个错误 (java.lang.NullPointerException),其中 RadioGroup 添加到了 LinearLayout。我能怎么做?谢谢, 马蒂亚