Android:如何获取对listView的引用?
我正在尝试将Android:如何获取对listView的引用?,android,Android,我正在尝试将地图视图与列表视图结合使用。我的理解是,我需要扩展MapActivity,然后获得一个对列表视图的引用,以便在我的类中使用。我的问题是无法获取对列表视图的引用 这是我的XML: <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/AbsoluteLayout1" android:layout_width="fill_parent"
地图视图
与列表视图
结合使用。我的理解是,我需要扩展MapActivity
,然后获得一个对列表视图的引用,以便在我的类中使用。我的问题是无法获取对列表视图的引用
这是我的XML:
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/AbsoluteLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_y="0dp"
android:clickable="true" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="268dp"
android:layout_y="151dp" >
</ListView>
</AbsoluteLayout>
出于某种原因,它说列表不是一个字段。我引用的有误吗
感谢您的帮助。应该是
listView = (ListView) findViewById(android.R.id.list);
但是,由于您没有使用列表活动
,因此不必将“@android:id/list”
<代码>“@+id/list”
(或任何自定义项)将起作用
通常,在需要时使用Android ID,例如使用ListActivity
/ListFragment
时,只有在自定义版面包含正确的ID时才能使用
另外,您应该使用MapFragments/SupportMapFragments
s,因为。AbsoluteLayout
已被弃用:)
listView = (ListView) findViewById(android.R.id.list);