Display data in ListView in reverse

2

I have a ArrayList of type ArrayList v_DtCajasTarimasLista and every time I enter new data they are added correctly and they are shown in the ListView, but what happens is that the last record entered appears to the bottom of the ListView and what I need is the opposite that appears at the beginning of the ListView.

  

How would you have to do to invert the order of values of ListView ?

I hope you can help me. Thanks

My code:

v_DtCajasTarimas = new ListaDtCajasTarimas();
                    v_DtCajasTarimas.setV_itemCode(codigo);
                    v_DtCajasTarimas.setV_status("");
                    v_DtCajasTarimas.setIdLinea(contCajas);
                    v_DtCajasTarimasLista.add(v_DtCajasTarimas);
adaptadorListaCajaTarima = new AdaptadorListaCajaTarima(getMyActivity(), v_DtCajasTarimasLista);
                    adaptadorListaCajaTarima.setObjetosGenerales(objetosGenerales);
                    adaptadorListaCajaTarima.setAppCompatActivity(getAppCompatActivity());
                    adaptadorListaCajaTarima.setItemFragment(this);
                    listViewCajaTarima.setAdapter(adaptadorListaCajaTarima);
    
asked by Javier fr 05.03.2018 в 21:23
source

1 answer

1

If you have a List of elements and you want to reverse the order you can use Collections.sort () or Collections.reverse () before adding the data to Adapter of your ListView :

Collections.sort(listElementos);

or

   Collections.reverse(listElementos);

In the case of your code, change the order before assigning them to Adapter , using Collections.reverse () will change the order of the elements within List :

Collections.reverse(v_DtCajasTarimasLista)
adaptadorListaCajaTarima = new AdaptadorListaCajaTarima(getMyActivity(), v_DtCajasTarimasLista);
    
answered by 05.03.2018 / 21:31
source