输入搜索查询后无结果(搜索对话框)

时间:2018-12-02 13:27:19

标签: java android firebase searchview

我正在尝试以很低的水平在firebase中搜索,没有什么复杂的。我做了一个浮动操作按钮,该按钮调用onSearchRequested()并显示搜索对话框。但是,如果我尝试在对话框中写一些东西,然后按Enter键,则绝对不会发生任何事情。这是我的代码:

        //searchable
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        //doMySearch(query);
        searchReference = FirebaseDatabase.getInstance().getReference().child("offers").child(userCountry).child(userCity);
        ValueEventListener searchListener = new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                ArrayList<Offer> searchlist = new ArrayList<>();
                for (DataSnapshot childDataSnapshot : dataSnapshot.getChildren()) {
                    String storeName = childDataSnapshot.child("store_name").getValue(String.class);
                    String offerTitle = childDataSnapshot.child("offer_title").getValue(String.class);
                    String category = childDataSnapshot.child("category").getValue(String.class);
                    String price = childDataSnapshot.child("price").getValue(String.class);
                    if (storeName.toLowerCase().contains(query.toLowerCase()) || offerTitle.toLowerCase().contains(query.toLowerCase()) || category.toLowerCase().contains(query.toLowerCase())) {
                        Offer offer = new Offer(storeName, offerTitle, price, category);
                        //add this to custom array adapter
                        searchlist.add(offer);
                        //create adapter
                        OfferAdapter adapter = new OfferAdapter(OffersFeedActivity.this, searchlist);
                        listView.setAdapter(adapter);
                    }
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        };
        searchReference.addValueEventListener(searchListener);
    } 

(可能是要随活动一起加载的原始列表会覆盖搜索后需要打印的列表吗?)我尝试调试(同样,没有什么复杂的东西,我不是那么好),看起来像这些行永远不会执行...

0 个答案:

没有答案