- Error hints
- Cause of error
- Reference links
Error message:
At Android.widget.abslistview$recyclebin.addscrapview (abslistview.java:)
When I wrote several different item layouts to the ListView in Android, I encountered an array out-of-bounds error in the header, which I had encountered before, but this time I had a re-understanding of the cause of the error.
Cause of Error:
When writing multiple item entries to the ListView, we need to rewrite the getitemviewtype () and Getviewtypecoun () two methods in the adapter adapter, which we typically Getitemviewtype () makes a distinction between the specific item (the return value types of both methods are of type int ) so that the different layout layouts are loaded in GetView () , while the The Getviewtypecount () method defines the number of different item types that cause the error in the header to appear, which can be explained by using a word from StackOverflow : "The Item view type you was returning from Getitemviewtype () is >= getviewtypecount (). " The Chinese means that the value of getviewtypecount () must be greater than the value of getitemviewtype () , and conversely, the error in the header will appear, usually we are from 1 Starting with different item types, for example, for chestnuts, we set the item type of type 1 and type 2, and then return 2 in the Getviewtypecount () method, so that the value of Getviewtypecount () is Typ When E is 2, the return value is equal, so the data out-of-bounds error appears in the header, usually we set the type value to count from 0 to ensure that the type of the maximum value is not greater than the return value of the Getviewtypecount () method, Getitemviewtype () The comments in the source code also remind us that "integers must is in therange 0 to {@link #getViewTypeCount}-1".
Reference Links:
http://lmbj.net/blog/arrayindexoutofboundsexception/
Http://www.cnblogs.com/xitang/p/3197158.html
At Android.widget.abslistview$recyclebin.addscrapview (Abslistview.java:)