安卓:自定义分隔符(甚至项目)中的ListView depening对项目的内容
我已经与约含地设有评级信息项目一个ListView 和距离到当前位置。
I've a ListView with items containing information about places with a rating and the distance to the current location.
该项目被分成两组:
- 在第1组:500米范围内
- 第2组:500米 - 1公里
- 在第3组:1公里 - 1.5公里
- ...
Withing这些群体中的项目由他们的等级排序。
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
说如500米 - 1公里的后跟该组中所有的的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许可证2.0的优势。只需把它交替组头的TextView
和适配器
含S的内容的每个部分的价值。
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 TextView
s and Adapter
s containing each section's worth of content.
或者,你可以偷看所有这些并推出他们的行为到现有的适配器
类。关键是要回报你的的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()
.