我需要将活动设置为“暂停”,以便搜索功能起作用

问题描述

我正在使用“编辑文本”来包括搜索以过滤RecyclerView的数据,即使它可以正常工作,我也需要将活动暂停并恢复,以使其进行更改(例如。打开另一个活动,然后返回到RecyclerView。

我不知道为什么会这样,并且想使用正确的方法来解决这个问题。

活动:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_products);
        searchText = findViewById(R.id.searchText);
        buttonAddProduct = findViewById(R.id.button_add_product);
        buttonAddProduct.setVisibility(View.VISIBLE); //Make add product button visible for this activity
        buttonAddProduct.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(AdminControl.this,SingleProductAdmin.class));
            }
        });


        setUpProductsView(productRef);

        //Search view
        searchText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s,int start,int count,int after) {

            }

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

            @Override
            public void afterTextChanged(Editable s) {
                Toast.makeText(getApplicationContext(),"text after changed",Toast.LENGTH_SHORT).show();
                if (s.toString() != null) {

                    //create query
                    Query searchQuery = productRef.orderBy("name")
                            .startAt(s.toString())
                            .endAt(s.toString() + "\uf8ff");

                    //build activity based on that query
                    setUpProductsView(searchQuery);
                } else {
                    setUpProductsView(productRef);
                }
            }
        });


    }


    private void setUpProductsView(Query query) {
        //set view
        FirestoreRecyclerOptions<Product> options = new FirestoreRecyclerOptions.Builder<Product>()
                .setQuery(query,Product.class)
                .build();

        adapter = new ProductAdapter(options,false);
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);




    
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...