【发布时间】:2017-11-13 06:06:29
【问题描述】:
如果我输入entity.about = "phone" 和test = "phone",则搜索列表会更新,但如果我输入entity.about = "this is phone" 和test = "phone",则搜索列表不会更新。
public void onSearchConfirmed(final CharSequence text) {
productsRef = FirebaseDatabase.getInstance().getReference("products");
searchList.clear();
final String test = text.toString();
productsRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
ProductEntity entity = postSnapshot.getValue(ProductEntity.class);
if(entity.about.contains(test) || entity.vendor_address.contains(test)) {
searchList.add(entity) ;
}
}
}
}
}
【问题讨论】:
-
您能否发布一个可重现的问题示例?你所描述的不应该发生。
-
尝试打印 entity.about 并在 if 条件之前测试值,并在 if 执行之前检查实际值。
-
我找到了。这是因为我在搜索之前没有添加 .tolowercase。
-
@RahulMishra 发帖回答并接受你的回答。
标签: java android string firebase if-statement