0

I'm getting myself in a muddle with an ArrayAdapter I'm trying to put together. I've got a constructor, Person, which is used to put together people to go in a list. I'm then putting together an ArrayList of type Person to make a readable list.

I then put together an ArrayAdapter so that the list can be seen in a ListView, but I'm constantly getting "Cannot resolve constructor" with my code.

I've tried countless possible solutions on this site including trying to use getActivity() or this in place of PeopleActivity.this, but I just cannot get my code to compile. I've also tried referencing my constructor class in the ArrayAdapter, but that just gives me an error that it's not an enclosing class.

Person.class (constructor)

import android.text.Editable;

public class Person {

public Person Person;

private Editable personName;

public Person(Editable a) {
    personName = a;
}

public void setName(Editable personName){
    this.personName = personName;
}

public Editable getName() {
    return personName;
}
}

PeopleActivity - populateListView

ArrayList<Person> peoplelistv = new ArrayList<Person>();

...

private void populateListView() {
            ListView list = (ListView) findViewById(R.id.peopleListView);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(PeopleActivity.this, android.R.layout.simple_list_item_1, peoplelistv);

            list.setAdapter(adapter);
        }

Any ideas folks?

Thanks

0

1 Answer 1

2

You are declaring the ArrayAdapter as ArrayAdapter<String>. However, the third parameter that you are passing to the constructor is neither a String[] nor a List<String>. If you are trying to wrap an ArrayList<Person> in an ArrayAdapter, it needs to be an ArrayAdapter<Person>, not ArrayAdapter<String>.

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

1 Comment

Thank you so much, how I missed that I do not know, life saver!

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.