简体   繁体   English

ListView与节标题问题

[英]ListView with section header problem

Hi I'm adding section headers for my listView, there are few methods on the web. 嗨,我要为我的listView添加节标题,网络上很少有方法。 Since I'm using simpleCursorAdapter to manage my listView, I adopted phil bogle's method. 由于我使用simpleCursorAdapter来管理listView,因此我采用了phil bogle的方法。 http://thebogles.com/blog/2010/02/section-headers-for-android-listviews/ http://thebogles.com/blog/2010/02/section-headers-for-android-listviews/

The error occurred at this part of the code: 错误发生在代码的这一部分:

09-06 11:06:43.460: INFO/System.out(563): Sun, 05 Sep 2010 11:41:53  (dateString)
09-06 11:06:43.460: INFO/System.out(563): Wed, 01 Sep 2010 21:58:06  (preDate)
09-06 11:06:43.460: INFO/System.out(563): 120.0                      (record)
09-06 11:06:43.820: INFO/System.out(563): Sun, 05 Sep 2010 17:47:26  (dateString)
09-06 11:06:43.820: INFO/System.out(563): Sun, 05 Sep 2010 11:41:53  (preDate)
09-06 11:06:43.820: INFO/System.out(563): 112.0                      (record)

This is the LogCat shows how they compare while I scroll up the list: 这是LogCat展示了当我向上滚动列表时它们如何进行比较:

 09-06 11:06:43.460: INFO/System.out(563): Sun, 05 Sep 2010 11:41:53 (dateString) 09-06 11:06:43.460: INFO/System.out(563): Wed, 01 Sep 2010 21:58:06 (preDate) 09-06 11:06:43.460: INFO/System.out(563): 120.0 (record) 09-06 11:06:43.820: INFO/System.out(563): Sun, 05 Sep 2010 17:47:26 (dateString) 09-06 11:06:43.820: INFO/System.out(563): Sun, 05 Sep 2010 11:41:53 (preDate) 09-06 11:06:43.820: INFO/System.out(563): 112.0 (record) 

The correct output should be: 正确的输出应为:
Sun, 05 Sep 2010 周日,2010年9月5日
112 112
120 120

But when I scroll up, the setViewValue calls 120 first and compare with preDate(show above), it becomes: 但是当我向上滚动时,setViewValue首先调用120并与preDate(如上所示)进行比较,它变为:
Sun, 05 Sep 2010 周日,2010年9月5日
112 112
Sun, 05 Sep 2010 周日,2010年9月5日
120 120

So how can I make the section headers fixed after creating the headers? 那么创建标题后如何固定节标题呢? Why setViewBinder been called while scrolling? 为什么滚动时调用setViewBinder? Any suggestions on this? 有什么建议吗? Thanks! 谢谢!

You might also take a look at very simple project here: http://code.google.com/p/android-section-list/ . 您还可以在这里查看一个非常简单的项目: http : //code.google.com/p/android-section-list/ Inspiration came from iOS's section list (comes out of the box in iOS). 灵感来自iOS的部分列表(在iOS中是开箱即用的)。

See the ListView with section headers widget here, this may help you. 请在此处查看带有部分标题的ListView小部件,这可能会对您有所帮助。 It works similarly to the default Contacts application. 它的工作方式类似于默认的“联系人”应用程序。

http://code.google.com/p/android-amazing-listview/ http://code.google.com/p/android-amazing-listview/

So how can I make the section headers fixed after creating the headers? 那么创建标题后如何固定节标题呢?

Have isHeaderVisible() work properly, I guess. 我猜想isHeaderVisible()可以正常工作。 Near as I can tell, that is where your problem lies. 据我所知,这就是您的问题所在。

Why setViewBinder been called while scrolling? 为什么滚动时调用setViewBinder?

Because rows are recycled when they are scrolled. 因为行在滚动时被回收。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM