Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android- ArrayAdapter constructor

I am going through this tutorial on Android here http://www.vogella.com/articles/AndroidDebugging/article.html

And in the exercise it gives some code with a fault. It says the problem is in here

public MyArrayAdapter(Context context, List<String> values) {
   super(context, android.R.layout.simple_list_item_1);
   this.context = context;
   this.values = values;
}

This is a constructor for a defined class MyArrayAdapter that extends ArrayAdapter. The tutorial says that the call constructor for the super class ArrayAdpater is wrong. Well I tried debugging it, I don't see what the problem is. Any insight, maybe I don't understand the ArrayAdapter concept well.

like image 495
Ryan Cori Avatar asked Jul 25 '26 12:07

Ryan Cori


1 Answers

Your constructor is wrong

public MyArrayAdapter(Context context, List<String> values) {

Look at the ArrayAdapter Docs and there is no constructor which takes these arguments

Probably the simplest is to use this constructor

ArrayAdapter(Context context, int resource, List objects)

and add your layout file for the other parameter. Also, change your super call accordingly.

like image 164
codeMagic Avatar answered Jul 28 '26 01:07

codeMagic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!