2014-10-17 106 views
0

我環顧四周尋找各種解決方案,但找不到解決問題的任何東西。ListView項目不顯示

我的列表視圖佈局(較大的佈局的一部分):

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/white" 
    android:layout_marginTop="@dimen/activity_horizontal_margin" 
    android:padding="@dimen/activity_horizontal_margin"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:text="Advantage" 
      android:layout_toLeftOf="@+id/tvAdvLevel"/> 

     <TextView 
      android:id="@+id/tvAdvLevel" 
      android:layout_width="@dimen/etOneChar" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:textStyle="bold" 
      android:text="Level" 
      android:gravity="center_horizontal"/> 

    </RelativeLayout> 

    <ListView 
     android:id="@+id/listAdvantages" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </ListView> 

</LinearLayout> 

我的代碼來測試填充它(從一個片段):

String[] strings = {"test 1", "test 2"}; 
ListView list = (ListView) view.findViewById(R.id.listAdvantages); 
list.setAdapter(new ArrayAdapter<String>(
    getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, strings)); 

結果(空列表視圖):

enter image description here

它確實似乎調整與數量它接收的數組項目。沒有一個只是出現。

+0

您使用的是對自定義的ListView,看atbthis政黨成員也可以幫助ü,中庸之道改變與你TEM的佈局,也apdute數據更對象把在ListView – 2014-10-17 18:49:29

+0

我已經嘗試過,結果相同。這就是爲什麼我正在測試,看看這個簡單的設置是否會起作用,事實並非如此。 – 2014-10-17 18:50:50

回答

0
  • 我不認爲這是很好的做法,使ListView高度wrap_content。嘗試使它match_parent

  • 同時指定父母LinearLayout中的vertical的方向默認情況下,它不是您想要的horizontal

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:layout_marginTop="@dimen/activity_horizontal_margin" 
    android:padding="@dimen/activity_horizontal_margin" 
    android:orientation="vertical" > 
    
    <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 
    
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:textStyle="bold" 
         android:text="Advantage" 
         android:layout_toLeftOf="@+id/tvAdvLevel"/> 
    
        <TextView 
         android:id="@+id/tvAdvLevel" 
         android:layout_width="@dimen/etOneChar" 
         android:layout_height="wrap_content" 
         android:layout_alignParentRight="true" 
         android:textStyle="bold" 
         android:text="Level" 
         android:gravity="center_horizontal"/> 
    
    </RelativeLayout> 
    
    <ListView 
        android:id="@+id/listAdvantages" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
    </ListView> 
    

+0

這使情況變得更糟,現在它似乎並沒有顯示出來。 http://i.imgur.com/onzcC5y.png?1?7927 – 2014-10-17 19:01:02