我正在尝试使用以下代码

时间:2017-05-30 13:58:34

标签: android firebase firebase-realtime-database firebaseui

我遇到的问题是我可以根据名称中的数字进行搜索,但任何其他文本都没有显示。基本上如果孩子的名字是1212 NW Drive,我可以搜索1212部分而不是名称的文本。

这是我基于EditText构建适配器的代码。

    mSearchText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mSearchInput = mSearchText.getText().toString().toLowerCase();

            if (mAutoCompleteSearchAdapter != null) mAutoCompleteSearchAdapter.cleanup();

            RecyclerView mHomeRecycler = (RecyclerView) findViewById(R.id.home_recycler_view);

                mAutoCompleteSearchAdapter = new AutoCompleteSearchAdapter(
                        BusinessesModel.class,
                        R.layout.business_listings,
                        BusinessViewHolder.class,
                        mSearchQuery = mDatabase.orderByChild("name").startAt(mSearchInput).endAt(mSearchInput + "~")) {
                };

                mHomeRecycler.setAdapter(mAutoCompleteSearchAdapter);
            }
    });

这是我的FirebaseRecyclerAdapter的代码。

public class AutoCompleteSearchAdapter extends FirebaseRecyclerAdapter<BusinessesModel, BusinessViewHolder> {


  public AutoCompleteSearchAdapter(Class<BusinessesModel> modelClass, int modelLayout, Class<BusinessViewHolder> viewHolderClass, Query ref) {
    super(modelClass, modelLayout, viewHolderClass, ref);


  }

  @Override
  protected void populateViewHolder(BusinessViewHolder viewHolder, final BusinessesModel model, int position) {

    viewHolder.setBusinessName(model.getName());
    viewHolder.setBusinessCategory(model.getCategory());

    if (model.getLogoURL() != null) {
        viewHolder.setBusinessLogo(getApplicationContext(), model.getLogoURL());
    } else {

    }

    viewHolder.setOnClickListener(new BusinessViewHolder.ClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Intent intent = new Intent(getApplicationContext(), DealDetailsActivity.class);
            intent.putExtra("name", model.getName());
            intent.putExtra("headerImg", model.getDailyDealLogoURL());
            intent.putExtra("logoImg", model.getLogoURL());
            intent.putExtra("freeDeal", model.getIsFreeDeal());
            intent.putExtra("dealOne", model.getDealOne());
            intent.putExtra("detailsOne", model.getDetailsOne());
            intent.putExtra("dealTwo", model.getDealTwo());
            intent.putExtra("detailsTwo", model.getDetailsTwo());
            intent.putExtra("dealThree", model.getDealThree());
            intent.putExtra("detailsThree", model.getDetailsThree());
            getApplicationContext().startActivity(intent);
        }
    });

}

以下是数据库中JSON的片段。

[ {
  "blue" : 84,
  "category" : "Sporting Goods",
  "dealOne" : "10% Off",
  "dealThree" : "$1 Off",
  "dealTwo" : "$5 Off",
  "detailsOne" : "Cannot be combined with any other offer.",
  "detailsThree" : "Cannot be combined with any other offer.",
  "detailsTwo" : "Cannot be combined with any other offer. Cannot be combined with any other offer. Cannot be combined with any other offer. Cannot be combined with any other offer.",
  "featuredOrderField" : 1,
  "green" : 99,
  "isDailyDeal" : "yes",
  "isFeaturedDeal" : "yes",
  "isFreeDeal" : "yes",
  "name" : "Dick's Sporting Goods",
  "orderField" : 100,
  "red" : 43
}, {
  "blue" : 94,
  "category" : "Golf",
  "dealOne" : "$5 off",
  "detailsOne" : "$5 off a round of 18 hole with a cart. Also includes free small basket of range balls.",
  "featuredOrderField" : 100,
  "green" : 153,
  "isDailyDeal" : "yes",
  "isFeaturedDeal" : "yes",
  "name" : "Quail Heights Country Club",
  "orderField" : 100,
  "red" : 100
}, {
  "blue" : 115,
  "category" : "Fast Food",
  "dealOne" : "$2 Off",
  "detailsOne" : "Cannot be combined with any other offer. Participating locations: US HWY 90 and Main St.",
  "green" : 43,
  "isDailyDeal" : "yes",
  "isFeaturedDeal" : "yes",
  "name" : "Taco Bell",
  "orderField" : 100,
  "red" : 92
}, {
  "blue" : 0,
  "category" : "Resturants",
  "dealOne" : "10% off",
  "detailsOne" : "Cannot be combined with any other offer.",
  "green" : 53,
  "isFeaturedDeal" : "yes",
  "isFreeDeal" : "yes",
  "name" : "1000 Degrees Neapolitan Pizzeria",
  "orderField" : 1,
  "red" : 223
}, {
  "blue" : 37,
  "category" : "Resturants",
  "dealOne" : "$1 off",
  "detailsOne" : "Order must be at least $5 and cannot be combined with any other offer.",
  "green" : 30,
  "isFeaturedDeal" : "no",
  "isFreeDeal" : "yes",
  "name" : "Moe's Southwestern Grill",
  "orderField" : 3,
  "red" : 203
}, {
  "blue" : 0,
  "category" : "Resturants",
  "dealOne" : "$5 off a $25 order",
  "dealTwo" : "10% off",
  "detailsOne" : "Order must be $25 before the $5 coupon can be applied.",
  "detailsTwo" : "Cannot be combined with any other offer.",
  "green" : 210,
  "isFeaturedDeal" : "yes",
  "name" : "Buffalo Wild Wings",
  "orderField" : 2,
  "red" : 255
} ]

0 个答案:

没有答案
相关问题