开发者

adapter getCount and listView getChildCount are not equal

开发者 https://www.devze.com 2023-02-22 13:24 出处:网络
I\'m trying to set some tests for my android app, and I\'m testing that the creation of an entry in the database is displayed in my ListView.

I'm trying to set some tests for my android app, and I'm testing that the creation of an entry in the database is displayed in my ListView.

here is some code snippet:

mDbHelper.createAccount();
assertEquals(1, mAccountListAdapter.getCount());
assertEquals(1, mAccountList.getChildCount());

the first assert works fine but in the second, getChildCount return开发者_如何学Go 0.

So the adapter is good, but the listView does not display it?

When I test it manually, the feature works though.


mAccountList.getChildCount() refers to the ViewGroup's method that returns the number of the views that this view contains, it's not ListView's method itself. So your assertion is invalid.


The getCount() method returns the number of items contained in the list The getChildCount() method returns the number of items visible in the screen.


getCount() returns you a count of items in Adapter (total in list), getChildCount() is a ViewGroup method that returns you number of subviews. ListView actively reuses views so if your list has 1000 items getCount() will return 1000, getChildCount() - around 10 or so...

0

精彩评论

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