2015-07-10 40 views
0

我有一個客戶名單show.In的XML我有一個grirdviewConvertview在getview()來空只在第一時間Baseadapter

 <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 

     <GridView android:id="@+id/customer_list" 
      style="@style/Widget.SampleDashboard.Grid" 
      android:layout_width="match_parent" 
      android:layout_marginTop="10dp" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:paddingLeft="@dimen/horizontal_page_margin" 
      android:paddingRight="@dimen/horizontal_page_margin" 
      android:paddingBottom="@dimen/vertical_page_margin" 
      android:scrollbarStyle="outsideOverlay" /> 

     </LinearLayout> 
    </ScrollView> 

在我使用的是客戶陣列填充適配器代碼。該Baseadapter的getview看起來像下面

@Override 
    public View getView(int position, View convertView, ViewGroup container) { 
    String todayortomorrow; 
    if (convertView == null) { 
     convertView = getLayoutInflater().inflate(R.layout.customer_detail_list, 
       container, false); 
    } 
    return convertview; 
    } 

我,這是獲得僅顯示一個單一的客戶活動見。原因是convert視圖只在第一次出現null。第二次它不會爲空。如何顯示列表中的所有客戶?

+0

您在'getview()'中的客戶數組''???發佈您的適配器類代碼,並且您沒有爲gridview項目聲明任何視圖,那麼您只是誇大了gridview項目佈局的'customer_detail_list'佈局。 – Pankaj

+0

這不是錯誤(convertView不爲空)。這是適配器的工作方式。 –

+0

convertView!= null是視圖重用的全部概念,這意味着當您的適配器中有1000個項目時,您不必爲視圖充氣1000次,但只需少量,並在滾動時重複使用 – pskink

回答

2

我在活動中看到只有單個客戶正在顯示 。原因是convert視圖只在第一次出現null。 第二次它不會爲空。

這是正常的行爲。 Android分配一個相同類型的視圖池,足以填滿屏幕。這樣做是爲了避免浪費內存(想想會發生什麼,如果你需要顯示的行萬)

如何顯示所有的客戶 列表

的方便快捷解決方案是使用convertView,findViewById佈局的內容,並將相應的信息設置爲您的數據集

相關問題