I have an ArrayList of type ArrayList v_DtCajasTarimasLista and every time I enter new data it is correctly added and displayed in the ListView, but what happens is that the last record entered appears at the bottom of the ListView and what I need is the opposite of what appears at the top of the ListView.
How should I do to invert the order of values of the
ListView
?
I hope you can help me. Thank you
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);
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
yourListView
:either
In the case of your code changing the order before assigning them to the
Adapter
, using Collections.reverse() will change the order of the elements inside theList
: