0

我想改變我的Android應用程序,我實現了片段。在主要活動中,我從XML文件獲取內容,我想用listview填充片段。但不幸的是它不起作用,請你能幫助我嗎?這裏是代碼。 片段佈局文件:listview在listfragment不工作

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <ListView 
    android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#00FF00" 
     android:drawSelectorOnTop="false" /> 

     <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"  
     android:id="@+id/toptext"/> 

</LinearLayout> 

這是片段文件:

​​

回答

3

您只需要使用適當的ID在你的ListView:

android:id="@android:id/list" 
+0

我在改變了這個佈局文件,但我仍然得到一個運行時異常。 –

+0

現在它工作了,我改變了setAdapter爲setListAdapter並刪除了getlistview。但它是listView中的適當的id。 –