Reputation: 41
I am beginner in Android development. At the moment, I am working a calculator. I want to use GridView
in button part, but i have one error:
Caused by:java.lang.IllegalArgumentException: can't have a viewTypeCount < 1
First i make class ButtonAdapter
and implements ListAdapter
. But i cant understand this error.
Please help me
Upvotes: 3
Views: 1752
Reputation: 2529
Maybe you are missing some data in the Gridview:
check this tutorial it can help you understand what you missed.
http://www.firstdroid.com/2011/02/06/android-tutorial-gridview-with-icon-and-text/
BR, Adrian.
Upvotes: 1
Reputation: 1107
getViewTypeCount should return the number of different views your GridView will be using. This number is used internally by Android to optimize view creation.
If all of items in your grid view are the same type, you should return 1.
@Override
public int getViewTypeCount() {
return 1;
}
There should be at least one type of the view, and your implementation probably returns 0. That's why you're getting the exception.
Upvotes: 4