awesomeman3595
awesomeman3595

Reputation: 3

get a reference to a list inside another class

In my app I have a list of Trucks that are displayed in a lisview, and every Truck has a list of cases inside it. My question is how do I get a reference to that list of cases inside the truck from the main activity.

public class Truck  {

private String name;
public List<Roadcase> cases;


public Truck() {
cases = new ArrayList<Roadcase>();
}

public Truck(String name) {
    this.name = name;
    this.cases = new ArrayList<Roadcase>();
}

public String getName() {
    return name;
}

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

public void addRoadcase(Roadcase roadcases) {
    cases.add(roadcases);       
}

public void deleteRoadcase(Roadcase roadcases){
    cases.remove(roadcases);        
}
public int numberOfRoadcases(){
    return cases.size();
}   

public List<Roadcase> getList() {
    return cases;
}
}

my Truck class. Thanks in advance.

Upvotes: 0

Views: 121

Answers (1)

MByD
MByD

Reputation: 137362

You should call the method getList from your activity (

public List<Roadcase> getList() {
    return cases;
}

)

For example:

Truck truck = new Truck();
List<Roadcase> list = truck.getList();

Upvotes: 1

Related Questions