I'm having trouble figuring out how to add my information from an arraylist that is using a class, and adding the information to an array adapter in a list view. I'm trying to add the first name from this array.
How am I able to do that?
I have this separate class (not sure if the toString is correct):
public class PersonClass {
final private String firstName;
final private String lastName;
final private String birthday;
final private int personPic;
private PersonClass(String fName, String lName, String bDay, int pic) {
firstName = fName;
lastName = lName;
birthday = bDay;
personPic = pic;
}
public String toString() {
return firstName+" "+lastName+" "+birthday+" "+personPic;
}
public static void main(String args[]){
// Information for each person using the PersonClass
PersonClass person1 = new PersonClass("first name", "last name", "01/01/2000", R.drawable.pic1);
// ..... up to 10...
// ArrayList
final ArrayList<PersonClass> personList = new ArrayList<>();
// Add person data to array list
personList.add(person1);
personList.add(person2);
personList.add(person3);
personList.add(person4);
personList.add(person5);
personList.add(person6);
personList.add(person7);
personList.add(person8);
personList.add(person9);
personList.add(person10);
}
}
This is my array adapter.
final ArrayAdapter<String> arrayAd = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,???);
I can't just add the arraylist name to the adapter because the array has a class adding the information to it. But I just want to show the first name of the array on the list view.