'android.R.id.list'异常

当遇到“Your content mush have a listView whose id attribute is 'android.R.id.list'“异常时:
一般在继承ListActivity时候,我们可以不指定xml的layout文件,但是当我们使用setContentView(xx)指定xml的layout时,确定在此xml文件中我们定义如下view
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    </ListView>


否则就会出现异常。

原因:因为ListActivity中已经绑定了默认的ListView,如果我们重新给Activity绑定Layout时,需要保证已经存在的父类中的视图工作正常,所以需要加上上述视图。

猜你喜欢

转载自ideal46.iteye.com/blog/1751096