我在 firestore 中有 Name 数组列表。例如,如果用户愿意,可以输入 10 个人名,并将姓名作为数组添加到 firestore 中。现在我的列表视图显示只有 1 个用户输入姓名的数组列表 ..然后只显示一个用户名..帮我解决这个问题非常紧急
public class join_participants extends Fragment {
private ListView listView;
private final FirebaseFirestore db = FirebaseFirestore.getInstance();
ArrayList<String> userName = new ArrayList<>();
@SuppressLint("SetTextI18n")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_join_participants, container, false);
listView = view.findViewById(R.id.list_view);
db.collection("users")
.get()
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult())) {
userName = (ArrayList<String>) document.get("Name");
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_list_item_1, userName);
listView.setAdapter(adapter);
} else {
userName.clear();
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_list_item_1, userName);
listView.setAdapter(adapter);
}
});
return view;
}