当前位置: 代码迷 >> Android >> getListView()步骤找不到为什么.
  详细解决方案

getListView()步骤找不到为什么.

热度:65   发布时间:2016-05-01 12:40:51.0
getListView()方法找不到为什么..
  <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:paddingRight="5dp" />

    <TextView
        android:id="@id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FF0000"
        android:text="No data" />

xml 这么定义的话.

在Activity里面如何findViewById 或者什么方法拿到这个listview啊
------最佳解决方案--------------------
getListView()需要继承ListActivity才有
------其他解决方案--------------------
它是使用系统默认的id 必须是"@+id/android:list"
就直接继承ListActivity 然后 setListAdapter(adapter)就可以了。

自定义的话
ListView list=(ListView)findViewById(R.id.list);
list.setListAdapter(adapter) 
------其他解决方案--------------------
你自己都说了findviewById,就是这个方法,只不过这个R要用com.android.R.list