【发布时间】:2013-07-04 10:13:44
【问题描述】:
我知道如何在 android 中创建自定义列表视图。但就像在 iPhone 应用程序开发中一样,我们可以为每一行设置多个不同的 uicellview 样式。如果是的话,在android中是否有可能我们如何实现这一点。我们将不胜感激您的帮助
【问题讨论】:
我知道如何在 android 中创建自定义列表视图。但就像在 iPhone 应用程序开发中一样,我们可以为每一行设置多个不同的 uicellview 样式。如果是的话,在android中是否有可能我们如何实现这一点。我们将不胜感激您的帮助
【问题讨论】:
在 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;
}
【讨论】:
您可以通过膨胀多个 xml 布局文件并根据条件返回它们来实现这一点。
例如在适配器的 getview() 方法中
你可以这样做
for condition 1
inflate layout 1 and return view
for condition 2
inflate layout 2 and return view.
【讨论】: