【发布时间】:2016-03-29 17:16:27
【问题描述】:
我目前有两个 android spinners,Category 和 Ratings,我想使用 Firebase 中的数据进行过滤搜索。现在我一次只能搜索 1 个微调器,但我希望过滤器搜索包括 2 个微调器。
以下是检索评分的代码:
firebase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
shops = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (ds.child("ratings").getValue().toString().equals(userSelectRatings)) {
shopName = ds.child("shop_name").getValue().toString();
phoneNumber = ds.child("phone_no").getValue().toString();
categoryOfShop = ds.child("category").getValue().toString();
email = ds.child("email").getValue().toString();
shops.add(new Shop(shopName, categoryOfShop, phoneNumber, userSelectRatings, email));
initializeAdapter();
}
}
}
下面是检索商店类别的代码:
firebase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
shops = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (ds.child("category").getValue().toString().equals(userSelectCategory)) {
shopName = ds.child("shop_name").getValue().toString();
phoneNumber = ds.child("phone_no").getValue().toString();
ratingsOfShop = ds.child("ratings").getValue().toString();
email = ds.child("email").getValue().toString();
shops.add(new Shop(shopName, userSelectCategory, phoneNumber, ratingsOfShop, email));
initializeAdapter();
如何编辑我的代码,以便我可以按类别和评级过滤搜索,而不是一次只过滤一个?原因是因为两个微调器都有不同的听众,所以我不确定它是如何工作的。您的帮助将不胜感激!
【问题讨论】:
标签: android search filter spinner