奇数的ListView [英] Odd number ListView

查看:131
本文介绍了奇数的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个的ListView 这里显示的情况:的

I'm trying to make a ListView with the situation displayed here:

ListView控件项目会从数据库中装载很多的项目,如何在这取决于从数据库返回的数据。但不管怎么说,如果是1项或一百万,同样的模式应该被重复。
我绝对无能如何使这样的布局。任何人都可以举一个例子,另一个堆栈溢出问题的链接(因为我不知道这是什么会被要求看它自己..)与此类似问题或教程?我希望有人能帮帮我!先谢谢了。

The ListView items will be loaded from a database so how many items are in it depends on the data returned from the database. But anyways, if it's 1 item or a million, the same pattern should be repeated. I'm absolutely clueless how to make a layout like this. Can anyone give an example, a link to another Stack Overflow question (Since I've no clue what this would be called to look it up myself..) similar to this question or a tutorial? I hope someone can help me! Thanks in advance.

推荐答案

我认为你必须使用RecycleView。
适配器有方法来设置不同的行视图。

I think you have to use the RecycleView. Adapter have method to set different row view.

@Override
public int getItemViewType(int position) {
    // Define a way to determine which layout to use, here it's just evens and odds.
    return position % 2;
}

@Override
public int getViewTypeCount() {
    return 2; // Count of different layouts
}

如果(convertView == NULL){
    //您可以将此线移动到你的构造,充气服务将不会改变。

if (convertView == null) { // You can move this line into your constructor, the inflater service won't change.

 mInflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    if(getItemViewType(position) == 0)
        convertView = mInflater.inflate(R.layout.listview_item_product_complete, null);
    else
        convertView = mInflater.inflate(R.layout.listview_item_product_inprocess, null);
    // etc, etc...

如果您想了解更多信息,只是去通过Android recyler查看文档。

If you want more information just go through the android recyler View document.

这篇关于奇数的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆