0

I have the following DTO object that represents a contact:

public class ContactDTO {

    private String name;
    private String eMail;

    public ContactDTO(String name, String eMail){
        this.name = name;
        this.eMail = eMail;
    }

    public void setName(String name){
        this.name = name;
    }

    public String getName(){
        return this.name;
    }

    public void setEmail(String eMail){
        this.eMail = eMail;
    }

    public String getEmail(){
        return this.eMail;
    }

}

I want to get an array of ContactDTO from Contact Provider data, I've seen arround and I know how to populate a List View with that contact data; but I don't know how to get the fields of every contact for populate that ContactDTO.

Thanks.

svprdga
  • 2,171
  • 1
  • 28
  • 51

1 Answers1

0

Your problem would be that you receive back a list of Contact, not your own custom implementation.

First of all, i'd press to use the standard Contact if there is any way you can. It will have the same, and more info and methods.

If you need to add methods to this class, you can also see if your custom class can extends Contact and your problem is pretty much solved too.

If you insist on using your own class without extending Contact, you'll have to create a ContactDTO from each Contact. You could add a constructor to your ContactDTO, which takes a Contact as parameter and extract the wanted fields.

Stefan de Bruijn
  • 6,289
  • 2
  • 23
  • 31
  • I don't know exactly how to get that list of Contact, but I saw an answer for filling my ContactDTO here: http://stackoverflow.com/questions/8431897/get-first-and-last-name-of-a-contact-rather-than-single-display-name?rq=1 . Thanks. – svprdga Mar 14 '13 at 10:23