如何使用Firebase查询过滤android listview项目? [英] how to filter android listview items with firebase query?

查看:168
本文介绍了如何使用Firebase查询过滤android listview项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的firebase startAt查询,但它并没有做正确的过滤,例如,如果我想搜索产品名称牛奶,它没有显示名为牛奶,因为小写,因此如何实现它,所以它可以为这两种情况工作?

  b =(Button)view.findViewById(R.id.querybutton); 

b.setOnClickListener(new View.OnClickListener(){
$ b @Override
public void onClick(View v){

Firebase ref = new Firebase(https://socialshopping.firebaseio.com/Food/Product);
Query queryRef = ref.orderByChild(name)。startAt(searchP.getText()。toString()) ;

mActiveListAdapter = new ActiveListAdapter(getActivity(),Product.class,R.layout.single_active_list,queryRef);
mListView.setAdapter(mActiveListAdapter);
}
});


解决方案

Firebase不是 a搜索引擎。试图假装它,只会导致一个可怕的经验。但它是一个NoSQL数据库,这意味着你可以在其上构建多种类型的应用程序。包括许多搜索方案。

您有两个主要选项:


  1. Firebase

  2. 使用外部搜索引擎与Firebase结合使用



  3. 如果您停留在Firebase中,你必须按照你想查询的方式存储数据,即把它们全部保存为小写,然后把搜索条件转换为小写。



    另请参阅:


    I am using firebase startAt query but It does not doing right filtering for instance if i want to search product name "Milk" it did'not showing item named "milk" because of lower case so how to implement it so it could work for both cases?

    b = (Button)view.findViewById(R.id.querybutton);
    
    b.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
    
            Firebase  ref = new Firebase("https://socialshopping.firebaseio.com/Food/Product");
            Query queryRef = ref.orderByChild("name").startAt(searchP.getText().toString());
    
            mActiveListAdapter  = new ActiveListAdapter(getActivity(), Product.class, R.layout.single_active_list, queryRef);
            mListView.setAdapter(mActiveListAdapter);
        }
    });
    

    解决方案

    Firebase is not a search engine. Trying to pretend that it is, will just lead to an awful experience. But it is a NoSQL database, which means you can build many types of applications on it. Including many search scenarios.

    You have two main options:

    1. Stay within Firebase
    2. Use an external search engine in combination with Firebase

    If you stay within Firebase, you'll have to store the data in the way you want to query it, i.e. store them all lowercase and then translate the search terms to lowercase too.

    See also:

    这篇关于如何使用Firebase查询过滤android listview项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆