When filling Listview it becomes empty

Asked

Viewed 79 times

0

This is a shopping cart screen, where the product purchased is added to a Listview using an Arraylistadapter. So far everything is working. However, each product contains a list of additional and/or removed ingredients in undetermined numbers. So I added a Listview to the layout that is inflated and placed in the cart’s Listview and use the Adapter and Adapter to fill it, just not working.

The following flowchart shows the chronological order:

Fluxo

I have the code:

/* itens removidos e adicionados */
                        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        View linha = inflater.inflate(R.layout.item_carrinho, null, false);

                        ListView liv = (ListView) linha.findViewById(R.id.lista_sel); //lista de add e rem

                        //primeiro adicionados e suas respectivas quantidades
                        ArrayList<String[]> objetos = new ArrayList<String[]>();
                        objetos.add(adicionais); //(0)
                        objetos.add(adicionais_qtd); //(1)

                        AdaptadorItemCarrinho adaptadorItemCarrinho = new AdaptadorItemCarrinho(Carrinho.this,
                                R.layout.item_obs_carrinho, objetos);
                        if ((adaptadorItemCarrinho != null) && (liv != null))
                            liv.setAdapter(adaptadorItemCarrinho);

                        //limpa objetos anteriores e incrementa os removidos
                        objetos.clear();
                        objetos.add(removidos); //(0)
                        objetos.add(null); //(1)
                        AdaptadorItemCarrinho adaptadorItemCarrinhoRem = new AdaptadorItemCarrinho(Carrinho.this,
                                R.layout.item_obs_carrinho, objetos);
                        if ((adaptadorItemCarrinho != null) && (liv != null))
                            liv.setAdapter(adaptadorItemCarrinhoRem);

Adapterevery bit contains the code:

public class AdaptadorItemCarrinho extends ArrayAdapter<String[]> {
private String[] dados;
private String[] dados_qtd;
private Context contexto;
private int layout;

public AdaptadorItemCarrinho(Context context, int textViewResourceId, ArrayList<String[]> objects) {
    super(context, textViewResourceId, objects);
    if (objects.get(1) == null){
        this.dados = objects.get(0);
    }else {
        this.dados = objects.get(0);
        this.dados_qtd = objects.get(1);
    }
    contexto = context;
    layout = textViewResourceId;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    //return super.getView(position, convertView, parent);

    final View linha;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        linha = inflater.inflate(layout, parent, false);
    }else {
        linha = convertView;
    }

    if(dados_qtd == null) { //incrementando os ingredientes removidos
        TextView nome = (TextView) linha.findViewById(R.id.item_ingred_carrinho);
        nome.setText(dados[position]);
        ImageView rem = (ImageView) linha.findViewById(R.id.add_ou_rem);
        rem.setImageResource(android.R.drawable.ic_delete);

    }else { //incrementando os ingredientes adicionados
        TextView nome = (TextView) linha.findViewById(R.id.item_ingred_carrinho);
        nome.setText(this.dados[position]);
        TextView quantidade = (TextView) linha.findViewById(R.id.quantidade);
        quantidade.setText(this.dados_qtd[position]);
    }


    return linha;
}
}

But when running it doesn’t even show listview.

1 answer

0

Browser other questions tagged

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