2013-07-06 38 views
0

我知道如何在android中創建自定義列表視圖。但是就像在iPhone應用程序開發中一樣,我們可以爲每一行設置多個不同的uicellview樣式。如果是的話,是否有可能在android中如何實現這一點。您的幫助將不勝感激Android自定義列表視圖中每行的不同佈局樣式

+1

http://stackoverflow.com/questions/17370525/listview-adapter-with-arbitrary-number-of-row -types,不要神祕的用戶號碼的二/ 17370772#17370772。檢查這個。 – Raghunandan

回答

0

您可以通過膨脹多個xml佈局文件並根據條件返回它們來實現此目的。

例如適配器

您getview()方法中,你可以做這樣的

for condition 1 

inflate layout 1 and return view 

for condition 2 

inflate layout 2 and return view. 
1

使用您getView方法的項目的位置。

僞:

public View getView(int position, View recycledView, ViewGroup group) { 
    View view; 
    if(position == 1){ 
     view = View.inflate(context, R.layout.view1, null); 
    } else { 
     view = View.inflate(context, R.layout.view2, null); 
    } 

    // populate the view 

return view; 
} 

參考: http://developer.android.com/reference/android/widget/Adapter.html#getView(int, android.view.View, android.view.ViewGroup)

http://developer.android.com/reference/android/view/View.html#inflate(android.content.Context, int, android.view.ViewGroup)

相關問題