Prakhar
Prakhar

Reputation: 710

Custom Adapter shows error on super()

I am making a custom adapter extending ArrayAdapter. When I extend BaseAdapter, it works fine, but when I use ArrayAdapter, it shows error on super(). My Adapter code:

CustomAdapter.java

public class CustomAdapter extends ArrayAdapter {

private final Context context;
private List<String> Title=new ArrayList<String>();
private List<String> Dis=new ArrayList<String>();
private List<String> Desc=new ArrayList<String>();
public static  TextView title;
public CustomAdapter(Context context,List<String>title,List<String>dis,List<String> desc) {
    super(); //ERROR HERE

    this.context = context;
    this.Title=title;
    this.Dis=dis;
    this.Desc=desc;

}
@Override
public int getCount() {
    return Title.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.custom_adapter,parent, false);
    title = (TextView)v.findViewById(R.id.helloText);
    final TextView dis = (TextView)v.findViewById(R.id.dis);
    final TextView descr = (TextView)v.findViewById(R.id.descr);

    title.setText(Title.get(position));
    dis.setText(Dis.get(position));
    descr.setText(Desc.get(position));

    return v;
}
}

And I want to call it as:

CustomAdapter ad=new CustomAdapter(this,titles,dis,desc);

Where titles, dis,desc are lists.

Upvotes: 0

Views: 273

Answers (2)

Dimitar Mihailov
Dimitar Mihailov

Reputation: 11

take a look at java basics for explanation. This is an extract: "You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. This default constructor will call the no-argument constructor of the superclass. In this situation, the compiler will complain if the superclass doesn't have a no-argument constructor so you must verify that it does. If your class has no explicit superclass, then it has an implicit superclass of Object, which does have a no-argument constructor."

You could read the whole article here

And further you could take a look at ArrayAdapter source as 0X0nosugar suggested.

Upvotes: 1

Yatish
Yatish

Reputation: 531

You need to pass parameter to super(), replace super() with following

super(context,title,dis,desc);

Upvotes: 0

Related Questions