【发布时间】:2020-09-02 12:25:16
【问题描述】:
我正在尝试从列表中获取所选项目索引,并且数据已存储在 firestore 中,我尝试的是,
db.collection("Musicians").orderBy("DocumentID", Query.Direction.ASCENDING).limit(30).get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()){
List<DocumentSnapshot> snapshotslist= Objects.requireNonNull(task.getResult()).getDocuments();
(DocumentSnapshot document : snapshotslist) {
//--- This way is not working----------------------------------//
int index = snapshotslist.indexOf("Flkt8Fb0gWvO9xaUYR0V");//This method always return -1
//----This way is working--------------------------------//
int index = snapshotslist.indexOf(document);// This method is working and it gives all index of the list
但我只需要获取我输入的文档的索引。例如,
- Flkt8Fb0gWvO9xaUYR0V
- BpJQAYm7Y49XA2IZMGhE
- LTy4KuRpXTc5e7FK2I9o
- bxzM9drC9DWDieWEbFLl
我想得到输出为 2 的“LTy4KuRpXTc5e7FK2I9o”的索引。
【问题讨论】:
标签: java firebase google-cloud-firestore