When filling ListView it is empty

0

This is a shopping cart screen, where the purchased product 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 number. So I added a ListView to the layout that is inflated and placed in the Cart's ListView and I use the Carriage Adapter and Carriage AdapterRem to fill it, just not working.

The following flowchart shows the chronological order:

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);

Carriage Adapter 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;
}
}

However when running it does not even show the listView.

    
asked by anonymous 04.03.2017 / 22:39

1 answer

0

I found the problem, I was missing the reference to the first ListView, so I was returning ListView as null. Now the problem is another one: Update data in ListView with ArrayAdapter

    
05.03.2017 / 15:43