0

I am new in Android Programming. I was doing a sample on ListView with different type of rows. I created a CustomAdapter which is extended from ArrayAdapter

public class CustomAdapter extends ArrayAdapter<String> {
    public static final int TYPE_ODD = 0;
    public static final int TYPE_EVEN = 1;
    public static final int TYPE_WHITE = 2;
    public static final int TYPE_BLACK = 3;

    private final Context context;
    private final int resource;
    private ListViewItem[] objects;

    public CustomAdapter(Context context, int resource, ListViewItem[] objects) {
        super(context, resource, objects);
        this.context = context;
        this.resource = resource;
        this.objects = objects;
    }

Eclipse shows super(context, resource, objects); line as error "The constructor ArrayAdapter(Context, int, MainActivity.ListViewItem[]) is undefined"

I can't figure out why this is happening. Please help on this.

2 Answers 2

2

The data type in the angle brackets (<String>) needs to match the data type in the array you are supplying (ListViewItem[]). In your case, they do not.

Most likely, you should:

  1. Make this an ArrayAdapter<ListViewItem>

  2. Remove private ListViewItem[] objects, as it is unnecessary and will get you in trouble -- use getItem() to access the array from the superclass

Most likely, you do not need private final int resource either, as it is unlikely that you will be using it, though I cannot rule that out.

Sign up to request clarification or add additional context in comments.

Comments

1
public class CustomAdapter extends ArrayAdapter<ListViewItem> {
    public static final int TYPE_ODD = 0;
    public static final int TYPE_EVEN = 1;
    public static final int TYPE_WHITE = 2;
    public static final int TYPE_BLACK = 3;

    private final Context context;
    private final int resource;
    private ListViewItem[] objects;

    public CustomAdapter(Context context, int resource, ListViewItem[] objects) {
        super(context, resource, objects);
        this.context = context;
        this.resource = resource;
        this.objects = objects;
    }


----------
see the first line of answer just change this line

public class CustomAdapter extends ArrayAdapter<String>
to
public class CustomAdapter extends ArrayAdapter<ListViewItem>

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.