0

I am working with ArrayAdapters. I am a bit troubled to understand why a super method (not sure if its a keyword or method in this case?) is applied and introduced. Also, why is its middle constructor value 0?

Cheers.

public class AttractionAdapter extends ArrayAdapter<Attraction> {

public AttractionAdapter(Context context, ArrayList<Attraction> attractions) {
    super(context, 0, attractions);
}

2 Answers2

0

That is not a requirement of ArrayAdapters. That is simply Java: Why call super() in a constructor?

You must call super in the constructor of a derived class if the parent class does not have a constructor without parameters (otherwise the call is implicit and you can avoid to call super()). Here some details.

Just for testing, try to extend BaseAdapter. It's constructor does not have parameters -> it is not necessary to call super() (actually it is called, but you don't need to write it).

Community
  • 1
  • 1
Massimo
  • 3,436
  • 4
  • 40
  • 68
0

That is the constructor of the ArrayAdapter, with wchich you create a new AttractionAdapter. You don't need to call super there most of the time. You can look up what super does in the Java 7 documentation. Also, the 0 is where your item goes. The item which the adapter is going to "copy and paste" to create a list. For now, the adapter has no items to display.

Nikaoto
  • 319
  • 1
  • 6
  • 20