Closed Bug 798683 Opened 9 years ago Closed 9 years ago

Replace getChildCount() calls on ListView

Categories

(Firefox for Android Graveyard :: General, defect)

ARM
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 22

People

(Reporter: bnicholson, Assigned: gbrown)

References

Details

Attachments

(1 file)

In several places in our code (especially robocop tests), we call getChildCount() on a ListView to determine how many children it has. Problem is, this method is from ViewGroup and returns the number of items in the View, not the number of items in the entire list. ListViews destroy and reuse views as they come into view, so getChildCount() is really just the number of *visible* views. To count the number of children from the adapter, we should consider changing list.getChildCount() to list.getAdapter().getCount() where applicable.

I ran into this when running testAllPagesView on my Galaxy S. With the keyboard up, only 4 entries in the AwesomeScreen are visible, so this assertion was failing:
http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/tests/testAllPagesTab.java.in#61
You're right. I missed that in my patch review. Wes wrote the tests, CC'ing him.
Blocks: 814278
A number of our tests are probably failing because of this bug. I'll see if I can fix them.
Assignee: nobody → bnicholson
Depends on: 769919
No longer blocks: 814278
Depends on: 814278
No longer depends on: 814278
Is this what you had in mind?

There are a few remaining getChildCount() calls, but on ViewGroups.

https://tbpl.mozilla.org/?tree=Try&rev=df4b8aa6e0f5
Assignee: bnicholson → gbrown
Status: NEW → ASSIGNED
Attachment #717553 - Flags: review?(bnicholson)
Comment on attachment 717553 [details] [diff] [review]
replace getChildCount() calls on ListView

Yeah, looks good to me. Hopefully this will help.
Attachment #717553 - Flags: review?(bnicholson) → review+
https://hg.mozilla.org/mozilla-central/rev/5228ec314dc9
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 22
Depends on: 845632
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.