如何在同一个孩子中分开物品

时间:2018-11-07 15:02:36

标签: android firebase firebase-realtime-database

我创建了一个基于电影的android应用程序。我在此应用程序中有一个搜索选项。我想搜索带有类别,国家/地区,日期等的电影。Firebase是我的后端,我正在使用orderByChild(“ category”)。 ,然后输入THRILLER,西班牙,2015年。当我在搜索框中输入THRILLER时,我会得到所有此项目。我的问题是如何使这一类别分开即。如何在搜寻THRILLER时只获得THRILLER,或在搜寻框中输入国家/地区时才得到西班牙。如何分隔THRILLER,COUNTRY,DATE的孩子。对不起,我的英语不好。

This is my Firebase Databese

我的java类是

database = FirebaseDatabase.getInstance();
    MCC = database.getReference("All2SubActivity");


    recyclerView = (RecyclerView) findViewById(R.id.recycler_Indiansub);
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(new GridLayoutManager(this, 3));



    loadListIndianSub(categoryId);


    //SearchBar
    materialSearchBar = (MaterialSearchBar)findViewById(R.id.searchBar);
    materialSearchBar.setHint("Enter Movie Name or Movie Genre");
    //materialSearchBar.setSpeechMode(false);
    loadSuggest();
    materialSearchBar.setLastSuggestions(suggestList);
    materialSearchBar.setCardViewElevation(10);
    materialSearchBar.addTextChangeListener(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) {
            List<String> suggest = new ArrayList<>();
            for (String search:suggestList)
            {
                if (search.toLowerCase().contains(materialSearchBar.getText().toLowerCase()))
                    suggest.add(search);
            }
            materialSearchBar.setLastSuggestions(suggest);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    materialSearchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
        @Override
        public void onSearchStateChanged(boolean enabled) {
            if (!enabled)
                recyclerView.setAdapter(adapter);
        }

        @Override
        public void onSearchConfirmed(CharSequence text) {
            startSearch(text);

        }

        @Override
        public void onButtonClicked(int buttonCode) {

        }
    });


}

private void startSearch(CharSequence text) {
    SearchAdapter = new FirebaseRecyclerAdapter<IndianSubModel, IndianSubViewHolder>(
            IndianSubModel.class,
            R.layout.indiansub_items,
            IndianSubViewHolder.class,
            MCC.orderByChild("title").equalTo(text.toString())
    ) {
        @Override
        protected void populateViewHolder(IndianSubViewHolder viewHolder, IndianSubModel model, int position) {
            viewHolder.indiansub_TextTitle.setText(model.getTitle());
            Picasso.get().load(model.getImage())
                    .into(viewHolder.indiansub_image);

            final IndianSubModel local = model;
            viewHolder.setItemClickListner(new ItemClickListner() {
                @Override
                public void onClick(View view, int position, boolean isLongClick) {


                    Intent detailsIntent = new Intent(IndianSubActivity.this, IndianDetailActivity.class);
                    detailsIntent.putExtra("CategoryId", SearchAdapter.getRef(position).getKey());
                    startActivity(detailsIntent);
                }
            });

        }
    };
    recyclerView.setAdapter(SearchAdapter);
}


//SearchBar
private void loadSuggest() {

    MCC.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    for (DataSnapshot postSnapshot:dataSnapshot.getChildren())
                    {
                        IndianSubModel item = postSnapshot.getValue(IndianSubModel.class);
                        suggestList.add(item.getTitle());
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });


}

private void loadListIndianSub(String categoryId) {

    adapter = new FirebaseRecyclerAdapter<IndianSubModel, IndianSubViewHolder>(IndianSubModel.class,
            R.layout.indiansub_items,
            IndianSubViewHolder.class,
            MCC) {

        @Override
        protected void populateViewHolder(final IndianSubViewHolder viewHolder, final IndianSubModel model, final int position) {
            viewHolder.indiansub_TextTitle.setText(model.getTitle());
            Picasso.get().load(model.getImage())
                    .into(viewHolder.indiansub_image);




            final IndianSubModel local = model;



            viewHolder.setItemClickListner(new ItemClickListner() {
                @Override
                public void onClick(View view, int position, boolean isLongClick) {


                    Intent detailsIntent = new Intent(IndianSubActivity.this, IndianDetailActivity.class);
                    detailsIntent.putExtra("CategoryId", adapter.getRef(position).getKey());
                    startActivity(detailsIntent);
                }
            });








        }
    };

    recyclerView.setAdapter(adapter);
}

}

0 个答案:

没有答案