Create a set-get class like:
private class NameDetails{
    private final String id;
    private final String name;
    public NameDetails(String id, String name){
        this.id = id;
        this.name = name;
    }
    public String getid() {
        return id;
    }
    public String getname() {
        return name;
    }
}
Create a list containing the name and ids like:
List<NameDetails> namedetailssetget ;
namedetailssetget = new ArrayList<NameDetails>();
Now whenever you are getting name and ids,add them to the list like:
namedetailssetget.add(new NameDetails(id,name));
In this way you can add all your data to the list.
To retrieve:
Within the onItemclickListner of listview write:
if(namedetailssetget.size()>0){
    NameDetails item = namedetailssetget.get(position);
    String id=item.getid();
    String name=item.getname();
}
N.B. The above position is the position of the item of the listview clicked.