如何从2个不同的微调器加载recyclerview

q3qa4bjr  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(295)

我要做一个服装店的应用程序´我试着用2个微调器和一个循环视图进行过滤搜索。问题是我不知道´我不知道怎么过滤。数据从firebase下载。问题是,我想成为一个迪纳米克回收,所以如果我选择其中一个选择,我想看到的要求。所以我的问题是我不知道´我不知道怎么知道这两个纺纱机是用哪一个。这两个纺纱机必须单独工作,但它们是相互配合的。
这是我的密码。

String txtBrand,txtKind;
Spinner spinBrand,spinKind;
RecyclerView rv;
List<String>Brands;
List<Producto> productlist;
AdapterAllProducts adapterAllProducts;
public DatabaseReference mReference;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v =inflater.inflate(R.layout.filter_fragment, container, false);
    spinMarca=v.findViewById(R.id.spinnerBrand);
    spinTipo=v.findViewById(R.id.spinnerKind);
    rv=v.findViewById(R.id.rv);
    Brands= Arrays.asList(getResources().getStringArray(R.array.brands));
    mReference= FirebaseDatabase.getInstance().getReference("Product");
    spinBrand.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            txtBrand = Brands.get(i);
            loadRecycler(txtBrand);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    return v;
}

public void loadRecycler(final String Marca){
    rv.setLayoutManager(new LinearLayoutManager(getContext()));
    productslist= new ArrayList<>();
    adapterAllProducts = new AdapterAllProducts(productslist,getActivity());
    adapterAllProducts.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Product prod = productslist.get(rv.getChildAdapterPosition(v));
            String pid = prod.getPid();
            String name = prod.getName();
            String desc = prod.getDescription();
            String ref = prod.getReference();
            float pri = (float)prod.getPrize();
            int cant = prod.getQuantity();
            String brand = prod.getBrand();
            Preferencias.setPid(getActivity(),pid);
            Preferencias.setName(getActivity(),nombre);
            Preferencias.setPrize(getActivity(),pre);
            Preferencias.setReference(getActivity(),ref);
            Preferencias.setDesc(getActivity(),desc);
            Preferencias.setQuantity(getActivity(),cant);
            Preferencias.setBrand(getActivity(),brand);

            Fragment fragment = new ProductsFragment();
            FragmentManager ManagerUser = getFragmentManager();
            FragmentTransaction transactionUser = ManagerUser.beginTransaction();
            transactionUser.replace(R.id.contentfragment,fragmentuser);
            transactionUser.commit();

        }
    });
    rv.setAdapter(adapterAllProducts);

    Query q = mReference.orderByChild("brand").equalTo(brand);
    q.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {

            productoslist.clear();
            for (DataSnapshot Snapshot : snapshot.getChildren()
            ) {
                Product product = Snapshot.getValue(Product.class);
                productslist.add(product);
            }
            adapterAllProducts.notifyDataSetChanged();

        }

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

        }
    });
}}

我为我的英语道歉。它´这不是我妈的冷笑话。如果有人能帮我,我将非常感激他们。

qmelpv7a

qmelpv7a1#

基本思想是从两个方面来阅读 spinners 当用户试图更改其筛选器或用户取消您的筛选器弹出窗口时。这样,只需添加显示为第0个索引的空/空/默认文本的检查 spinner ```
String text1 = mySpinner1.getSelectedItem().toString()
String text2 = mySpinner2.getSelectedItem().toString()

相关问题