0

I know this has been solved a million times and yes i have searched, but it doesn't work for me.

The problem is that method super doesn't want proper arguments.

The code:

public class QuotesArrayAdapter extends ArrayAdapter<Map<Integer,List<String>>> {
private Context context;
Map<Integer,List<String>> Values;
static int textViewResId;
Logger Logger;

public QuotesArrayAdapter(Context context, int textViewResourceId, Map<Integer,List<String>> object) {
    super(context, textViewResourceId, object);   //<---- ERROR HERE
    this.context = context;
    this.Values = object;
    Logger = new Logger(true);
    Logger.l(Logger.TAG_DBG, "ArrayAdapter Inited");
}

What Eclipse says:

Multiple markers at this line
- The constructor ArrayAdapter<Map<Integer,List<String>>>(Context, int, Map<Integer,List<String>>) 
 is undefined
- The constructor ArrayAdapter<Map<Integer,List<String>>>(Context, int, Map<Integer,List<String>>) 
 is undefined

It wants super(Context, int) and that's not what i want

0

3 Answers 3

5

Look at the constructors available for ArrayAdapter.

ArrayAdapter(Context context, int textViewResourceId)
ArrayAdapter(Context context, int resource, int textViewResourceId)
ArrayAdapter(Context context, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int textViewResourceId, List<T> objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)

None of those matches your arguments.

Which one did you intend to invoke? Your T here is Map<Integer,List<String>>, but your constructor's object parameter is of exactly that type. If you want to use one of the constructors which requires a collection, you need to build that collection from that single object you've got.

The simplest approach is probably just to use:

public QuotesArrayAdapter(Context context, int textViewResourceId,
                          Map<Integer,List<String>> object) {
    super(context, textViewResourceId);
    add(object);
    ...
}
Sign up to request clarification or add additional context in comments.

3 Comments

Oh i got it! I changed arguments and it worked! thanks a lot!
@DrBigNik (While my answer is not superior.) By calling add(object) you will create a List<Map<Integer, List<String>>> with one item... I wouldn't put "efficient" among the potential adjectives for this Collection. I highly recommend restructuring your data to simply use a List or writing the adapter that you do want yourself. (I'll give Jon Skeet an upvote anyway for making it work.)
Yeah i think i will write my own Adapter, 'cause using a List will not be good in my situation. Thanks for your help.
1

Quite simply there is no constructor in ArrayAdapter that takes a Map...

You need to convert it into a List or primitive Array, if neither of those options work then you will have to extend BaseAdapter instead.

Comments

1

In additional you can use Arrays.asList(..)

public QuotesArrayAdapter(Context context, int textViewResourceId, Map<Integer,List<String>> object) {
    super(context, textViewResourceId,  Arrays.asList(object));   
.... 

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.