Android:ListView 中的自定义分隔符(甚至项目)取决于项目的内容 [英] Android: custom separator (or even item) in ListView depening on content of item

查看:17
本文介绍了Android:ListView 中的自定义分隔符(甚至项目)取决于项目的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView,其中包含有关具有评级的地点信息以及到当前位置的距离的项目.

I've a ListView with items containing information about places with a rating and the distance to the current location.

项目按组分类:

  • 第 1 组:500m 以内
  • 第 2 组:500m - 1km
  • 第 3 组:1 公里 - 1.5 公里
  • ...

对于这些组,项目按评分排序.

Withing these groups the items are sorted by their rating.

现在我通过我的自定义适配器(BaseAdapter 的扩展)将这些项目放到 ListView 中,效果很好.

Now I put out these items via my custom adapter (extension of BaseAdapter) into the ListView, which works perfectly.

但是,我想做的是在每个组的每个第一项之前放置一个分隔符.这个分隔符可以是一个 TextView 说例如500m - 1km 之后是该组中的所有 ListView 项目.

However, what I'd like to do is to put a separator before the each first item of each group. This separator can be a TextView saying e.g. 500m - 1km followed by all the ListView items in that group.

知道如何实现这一点吗?

Any idea on how to realize this?

推荐答案

这是一种实现,完全符合您的描述.

那个是 GPLv3,因为它派生自 这个实现,这是 GPLv3.

That one is GPLv3, because it is derived from this implementation, which was GPLv3.

你也可以使用我的 MergeAdapter,它有Apache License 2.0 的优势.只需将一组交替的标头 TextViewAdapter 包含每个部分的内容.

You can also use my MergeAdapter for this, which has the advantage of being Apache License 2.0. Just hand it an alternating set of header TextViews and Adapters containing each section's worth of content.

或者,您可以查看所有这些并将它们的行为滚动到您现有的 Adapter 类中.诀窍是在正确的位置返回您的 TextView 标头,并正确实施诸如 getViewTypeCount()getItemViewType() 之类的方法areAllItemsEnabled()isEnabled().

Or, you can peek at all of these and roll their behaviors into your existing Adapter class. The trick is to return your TextView headers at the right spot, and properly implement methods like getViewTypeCount(), getItemViewType(), areAllItemsEnabled(), and isEnabled().

这篇关于Android:ListView 中的自定义分隔符(甚至项目)取决于项目的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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