有什么方法可以将arrayList传递给alertDialog方法builder.setItems
,因为它正在接受字符串数组
public void getMember() {
ArrayList<String> MemberList = new ArrayList<>();
MemberList.add("tahir");
MemberList.add("usman");
MemberList.add("waqas");
AlertDialog.Builder builder = new AlertDialog.Builder(ManagerHome.this);
builder.setTitle("Member List");
builder.setIcon(R.drawable.ic_format_list_bulleted_black_24dp);
builder.setItems(MemberList, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
}
答案 0 :(得分:1)
您可以将MemberList
转换为数组,然后将其传递给setItems
方法。如下所示:
public void getMember() {
ArrayList<String> MemberList = new ArrayList<>();
MemberList.add("tahir");
MemberList.add("usman");
MemberList.add("waqas");
AlertDialog.Builder builder = new AlertDialog.Builder(ManagerHome.this);
builder.setTitle("Member List");
builder.setIcon(R.drawable.ic_format_list_bulleted_black_24dp);
builder.setItems(MemberList.toArray(new String[0]), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
}