Android: GridView

I'm starting to develop Android. I am currently working with a calculator. I want to use the GridViewbutton part, but I have one error:

Caused by:java.lang.IllegalArgumentException: can't have a viewTypeCount < 1

First I make a class ButtonAdapterand implement ListAdapter. But I can not understand this error.

Please help me

+3
source share
2 answers

getViewTypeCount should return the number of different views that the GridView will use. This number is used internally by Android to optimize the creation of views.

If all the elements in the form of a grid are of the same type, you must return 1.

@Override
public int getViewTypeCount() {
    return 1;
}

There must be at least one kind of representation, and your implementation will probably return 0. That's why you get an exception.

+4

Source: https://habr.com/ru/post/1764489/


All Articles