2013-07-06 36 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)

相关问题