简体   繁体   English

如何从 ArrayList 中获取数据<List>在另一个班级?

[英]How to get data from an ArrayList <List> in another class?

I'm using RecyclerView I have an Activity that queries my database and I insert this data into that ArrayList , and I want to list that data in another Activity.我正在使用RecyclerView我有一个查询我的数据库的 Activity 并将此数据插入该 ArrayList ,我想在另一个 Activity 中列出该数据。

This is where I query and add the data to the ArrayList这是我查询并将数据添加到 ArrayList 的地方

            String queryProduto = "SELECT" +
                    " Produto_Servico.ID, Produto_Servico.Descricao," +
                    " Produto_Estoque.EstoqueAtual, ValorVenda" +
                    " FROM" +
                    " Produto_Valor" +
                    " INNER JOIN" +
                    " Produto_Servico" +
                    " ON" +
                    " Produto_Servico.ID = Produto_Valor.ID_Produto" +
                    " INNER JOIN" +
                    " Produto_Estoque" +
                    " ON" +
                    " Produto_Estoque.ID_Produto = Produto_Servico.ID" +
                    " WHERE" +
                    " Produto_Estoque.EstoqueAtual > 0" +
                    " ORDER BY" +
                    " Produto_Servico.Descricao";
            Statement stmtP = connect.createStatement();
            ResultSet rsP = stmtP.executeQuery(queryProduto);


            String queryPessoa = "SELECT ID_Pessoa FROM Novo_Pedido";
            Statement stmtPS = connect.createStatement();
            ResultSet rsPS = stmtPS.executeQuery(queryPessoa);

            while (rsPS.next()){
                cod = rsPS.getString("ID_Pessoa");
            }




            if (rsP != null) {


                while (rsP.next()) {

                    id = String.valueOf(rsP.getString("ID"));
                    desc = rsP.getString("Descricao");
                    estoque = String.valueOf(rsP.getString("EstoqueAtual"));
                    valorDec = rsP.getBigDecimal(4);
                    qtdStr = String.valueOf(qtd);
                    valorStr = decimalFormat.format(valorDec);

                    String descFinal = desc;
                    String qtdFinal = qtdStr;
                    final BigDecimal[] valorFinal = {valorDec};
                    try {


                        listProdutosPedidosFinalizar.add(new ListProdutosPedidosFinalizar(descFinal, qtdFinal, valorFinal[0], BigDecimal.ZERO));
                        classeLists.setListProdutosPedidosFinalizar(listProdutosPedidosFinalizar);
                        produtosPedidosAdapter = new ProdutosPedidosAdapter(listProdutosPedidos, this, new ProdutosPedidosAdapter.OnClickListener() {


/*METHODS*/
                        produtosPedidosAdapter.notifyDataSetChanged();

                        listProdutosPedidos.add(new ListProdutosPedidos(id, desc, estoque, valorStr, qtdStr));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }

                    rvProdutosPedidos.setAdapter(produtosPedidosAdapter);
                    produtosPedidosAdapter.notifyDataSetChanged();
                    isSuccess = true;
                }

And now I want to list the listProdutosPedidos data in another Activity.现在我想在另一个活动中列出listProdutosPedidos数据。

将 listProdutosPedidos 列表定义为类的静态成员,然后使用 className.listProdutosPedidos 代码访问其中的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM