Android 以编程方式更改ExpandableList视图

Android 以编程方式更改ExpandableList视图,android,Android,我有一个ExpandableList和我实现的BaseExpandableListAdapter 现在,有时我需要显示其他xml内容,因此我尝试: ExpandableList.this.setContentView(R.layout.errorscreen); 但我得到了一个例外: 错误/AndroidRuntime(23948):java.lang.RuntimeException,您的内容必须具有id属性为“android.R.id.list”的ExpandableListView 现在

我有一个ExpandableList和我实现的BaseExpandableListAdapter

现在,有时我需要显示其他xml内容,因此我尝试:

ExpandableList.this.setContentView(R.layout.errorscreen);
但我得到了一个例外:

错误/AndroidRuntime(23948):java.lang.RuntimeException,您的内容必须具有id属性为“android.R.id.list”的ExpandableListView

现在,我被告知这样做是为了修复它:

add  ExpandableListView to your xml layout and set it's id to list. Like so:   
  <ExpandableListView android:id="@id/android:list" android:layout_width="fill_parent"android:layout_height="fill_parent"/>
将ExpandableListView添加到xml布局中,并将其id设置为list。像这样:

如何以编程方式执行此操作?

您正在将此活动的contentView设置为在名为errorscreen.xml的xml文件中定义的布局:

ExpandableList.this.setContentView(R.layout.errorscreen);
但是,您正在执行的活动扩展了ExpandableListActivity(我猜)。这样的活动需要xml中的ExpandableListView来显示其数据。现在只需打开errorscreen.xml并添加此元素

干杯