0

This question may sound stupid but I cannot help myself but ask here.

I know in Array adapter, getcount() method is used to return the number of elements to display in the list. I also know that we need to override it and return the size of the array or number of lists to display in the layout.

In many online blogs, I saw that the getcount() method is not overridden but still, the list is displayed and when I try to do it the same way, I do not get any lists displayed unless I override getcount() .

So my question is

1) Is it really necessary to override method to display lists? How does getcount method know how many lists to display without overriding it as it is done in many online blogs.

2) when it is not necessary to override getcount() and still get the views as intended.

I am just learning and hope you to understand. Thank you

2
  • Thank you , But is it possible to get views without overriding getcount() .Because in some online blogs they did not override and still they got the list data. Commented Oct 22, 2019 at 8:36
  • Don't confuse ArrayAdapter, BaseAdapter, ListAdapter. In ListAdapter you have to do everything yourself. ArrayAdapter takes an array and does everything it can for you. Commented Oct 22, 2019 at 8:39

1 Answer 1

2
  1. inside adapter (not list itself) - yes, you have to override this method and return number of items (e.g. straight from list.size())
  2. show these "many online blogs links", will verify. some adapters (like base ArrayAdapter) may have automated counting items, especially when they are passed in constructor in List - this class is well-known collection, so there is prepared adapter for this common usage, but if you have YourOwnClass populated by own resolution, then you have to extend adapter and handle counting by self
  3. show some code... always
Sign up to request clarification or add additional context in comments.

2 Comments

As you asked ,link to one such blog is given below when the getcount() is not overridden link
adapter under link is ArrayAdapter which takes List as parameter and have "automated" bypassing getCount() to list.size()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.