List in Android Studio

Asked

Viewed 133 times

0

I have a listview that brings data when I add it to mine ArrayAdapter. For example: adaptador.add("algum dado").

But I wanted this listview to bring data from a register of products, such as the name, quantity and price that are in Edittexts. The problem is that on my insert screen I can’t make reference to ArrayAdapter to add this data, because the list and insertion screen are two different screens.

If possible also, I would like you to display the total price of each value of the products added. The two list and insert screens are respectively "CarregarTelaLista()" and "Carregar Tela3()"

Follows the code:

public void CarregarTelaLista()
{
    setContentView(R.layout.lista);



    btnadd = (ImageButton) findViewById (R.id.btnadd);
    volte = (ImageButton) findViewById(R.id.volte);

    lstprodutos = (ListView)findViewById(R.id.lstprodutos);

    adaptador = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);

    adaptador.add("Produto: " + txtnome.getText().toString() + "Quantidade: " + txtquantidade + " Preco: " + txtpreco.getText().toString());

    lstprodutos.setAdapter(adaptador);

    //VOLTAR
    volte.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CarregarTela1();
        }
    });
    //ADICIONAR PRODUTOS
    btnadd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CarregarTela3();
        }
    });

}

    public void CarregarTela3()
    {
        setContentView(R.layout.tela3);


        spi = (Spinner) findViewById(R.id.spin);
        final ArrayAdapter adapter =  ArrayAdapter.createFromResource(this, R.array.unidade,
        android.R.layout.simple_spinner_item);
        spi.setAdapter(adapter);

     /*   ListView lstprodutos = (ListView) findViewById(R.id.lstprodutos);

        ArrayAdapter<addprodutos> adpProdutos = new ArrayAdapter<addprodutos>(this, android.R.layout.simple_list_item_1);

        lstprodutos.setAdapter(adpProdutos);  */

        btnvoltar3 = (Button) findViewById(R.id.btnvoltar3);
        insere = (Button) findViewById(R.id.insere);

        txtnome = (EditText) findViewById(R.id.txtnome);
        txtpreco = (EditText) findViewById(R.id.txtpreco);
        txtquantidade = (EditText) findViewById(R.id.txtquantidade);

        lstprodutos = (ListView)findViewById(R.id.lstprodutos);

        adaptador = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);

        insere.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if(txtnome.getText().toString().isEmpty() || txtpreco.getText().toString().isEmpty()){
                    Toast toast = Toast.makeText(getApplicationContext(),
                            "há campos vazios", Toast.LENGTH_LONG);
                    toast.show();
                }
else {
                    adaptador.add("Produto: " + txtnome.getText().toString() + "Quantidade: " + txtquantidade + " Preco: " + txtpreco.getText().toString());


                    CarregarTelaLista();

                }
                lstprodutos.setAdapter(adaptador);
            }
        });

1 answer

0

You have two insertion screens 'Carregartelalista' and 'Carregartela3' ?

You could try to insert the information on a screen and on another screen you load the Listview. By clicking on Listview you can play to an editing screen and on that screen you can make the logic of the amount x value. I could not understand very well what you are wanting. But I leave here my suggestion.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.