简体   繁体   中英

ListView with section header problem

Hi I'm adding section headers for my listView, there are few methods on the web. Since I'm using simpleCursorAdapter to manage my listView, I adopted phil bogle's method. 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:

 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
112
120

But when I scroll up, the setViewValue calls 120 first and compare with preDate(show above), it becomes:
Sun, 05 Sep 2010
112
Sun, 05 Sep 2010
120

So how can I make the section headers fixed after creating the headers? Why setViewBinder been called while scrolling? Any suggestions on this? Thanks!

You might also take a look at very simple project here: http://code.google.com/p/android-section-list/ . Inspiration came from iOS's section list (comes out of the box in iOS).

See the ListView with section headers widget here, this may help you. It works similarly to the default Contacts application.

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. Near as I can tell, that is where your problem lies.

Why setViewBinder been called while scrolling?

Because rows are recycled when they are scrolled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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