开发者

List View - scroll to bottom, WITHOUT skipping items

开发者 https://www.devze.com 2023-03-26 04:35 出处:网络
I have a ListView that\'s being populated from a custom CursorAdapter. Every item(-row) has a checkbox.

I have a ListView that's being populated from a custom CursorAdapter. Every item(-row) has a checkbox.

A couple of important facts before I explain the problem:

A. The checked/unchecked data is coming from the DB.

B. I save the location of every "checkbox" to a boolean array.

C. There is no way to know which checkbox is checked, without re-querying the until I scroll to it, since it is not loaded yet.

Problem is:

I am trying to create a "Clear All" button. 开发者_JAVA百科for every "checked" checkbox, I will have to update the column in the DB to "no".

I tried LV.scrollTo(lastItem), and then check if each row is checked or not:

    for (int i = 0; i < cursor.getCount(); i++) {
        boolean t = itemChecked.get(i); //check the array to see if this row is checked
        if (t == true) {
        //set to "no" in the DB
        }

but it seemed that it "skipped" over the rows between the one that were displayed on the very top and the very bottom. I figured it's happening because they are not getting rendered, and therefore not saving the "checked" state in the array.

Then I tried this little piece of code that will scroll through every 5 rows or so, but it still didn't work:

 int j = 0; 
//loop times is the array.count() over the amount of rows that fit in the screen 
     while(j < loopTimes){ 
 int n = j*fitToScreen;

 Listview.setSelection(n);

   j++ ;
 }

It just jumps straight to the bottom, without reading those rows.

My guess is that there's not enough time for the rows to render.

Is there any other way of scrolling down without skipping the rows, or accomplishing what that am trying to do?

Thanks in advance.

0

精彩评论

暂无评论...
验证码 换一张
取 消