I’m trying to build an AlertDialog using Builder. My dialog has to have multiple option the user can choose from. I found on android developers website that I can use builder.setItems(int, DialogInterface.onClickListener). my problem is that im trying to pass a List addresses instead of the int. I want the user to choose an option from the list of addresses. Here’s my code for illustration:
private List<Address> addresses;
protected void updateMap() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick an Address");
builder.setItems(addresses, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int choosenAddress) {
//address = addresses.get(choosenAddress); //choose result from the array
}
});
In the builder.setItems ..i get an error saying this argument does not take list.
SetItemstakes Charsequence Array as a parameter, so you will have to convertList<Address>toList<String>and then uselist.toarray()