我没有使用 ListActivity,因为我想扩展 FragmentActivity。相反,我尝试使用:
ListView lv = (ListView) findViewById(R.id.mainListView);
不幸的是 lv 为空。
在我的 xml 中我有:
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
我还尝试过对列表视图使用不同的 android id,例如使用 ListActivity 时必须使用的 ID,但它始终为 Null。
编辑:我试图在调用 setContentView 之前调用 findViewById。首先调用 setContentView 修复它。
正如 JRaymond 之前在评论中提到的,我需要在使用 findViewById 之前调用 setContentView。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)