Reputation: 137
I am trying to develop an app, where you speak a name and it will lookup your contacts and return all names like "Lars A., Lars B., Lars C.". I save all those names in an ArrayList and it works. Now I want to have a AlertDialog, so the User can select the right contact out of this list. I figured out, that it has to be a CharSequence, so I convert it before. But I think the list is empty, because I only see the alert message.
This site describes it very well, but uses static values, I need dynamic values: Android Developer Site.
Heres my code:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
CharSequence[] cs = namearray.toArray(new CharSequence[namearray.size()]);
builder.setMessage("Welche/n " + cname + " meinst du?");
builder.setItems(cs, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int item) {
//do something
} });
AlertDialog alert = builder.create();
alert.show();
Upvotes: 2
Views: 2288
Reputation: 691983
The documentation says:
Because the list appears in the dialog's content area, the dialog cannot show both a message and a list and you should set a title for the dialog with setTitle().
Upvotes: 5