我被添加了搜索栏,当我想输入数据在Firestore中不可用时,则TextView noDocumentAvailable可见;当我想输入数据在Firestore中可用时,则TextView消失。
代码:
private void searchDocument(String search) {
collectionReference.orderBy("documentName").startAt(search).endAt(search + '\uf8ff').get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
documentsList.clear();
if (task.getResult().size() < 0) { // not working for me
noDocumentAvailable.setVisibility(View.VISIBLE);
} else {
for (DocumentSnapshot documentSnapshot : task.getResult()) {
Documents documents = documentSnapshot.toObject(Documents.class);
documentsList.add(documents);
documentListAdapter.notifyDataSetChanged();
}
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(StartCounting.this, "Error : " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
最佳答案
更改此行
if (task.getResult().size() < 0) {
至
if (task.getResult().size() < 1) {
要么
if (task.getResult().size() == 0) {
列表的大小不能小于零
关于java - 当项目在Firestore中不可用时过滤搜索列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58767420/