The code is:
public class Organization {
private String name;
private Long id;
public Organization(){
}
public Organization(String name, Long id) {
super();
this.name = name;
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
The spinner is:
Spinner sp = (Spinner) navigationView.getMenu().findItem(R.id.brand_spinner).getActionView();
sp.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,contactList));
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String value = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(),""+value+"",Toast.LENGTH_SHORT).show();
}
});
How can I pass both name and id to the spinner and the should be listed in the spinner, by selecting the name in the spinner. Store the id of the name in the local variable.