2

I want to create my own ArrayAdapter calling just the super constructor that has only 2 parameters, the context and the resource layout id. The problem is that the getView method is never called if I use that constructor, but if I use the other constructors were I pass a List object parameter or an array, it will call my getView method. I tried to override the isEmpty method and still nothing, also this method is not called either.

Is there any way to make sure the getView method is called just using the super constructor with 2 parameters (context and resource layout id) ?

Thank you.

4
  • Please post some example code Commented Oct 4, 2014 at 18:22
  • Add your code.What have you tried? Commented Oct 4, 2014 at 18:24
  • in ArrayAdapter constructor method handle size of your list, if you don't , pass your list to constructor getView not called Commented Oct 4, 2014 at 18:25
  • Then what is the point of having a constructor were you can only pass the context and the resource layout id if you need to pass an array or a List object so he can determinate the size of the listview? Is there any way on how can I bypass this? Commented Oct 4, 2014 at 18:28

1 Answer 1

4

Since you're not passing a List to the super class when using the two-parameter constructor, you'll need to override the getCount() method to return the size of your List. Otherwise, the AdapterView will think there are zero items, and will not attempt to call getView(). For example:

@Override
public int getCount()
{
    return list.size();
}
Sign up to request clarification or add additional context in comments.

Comments

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.