I used the search button but I only found solutions for custom list views. I have a really simple ListView in my activity, that should only show the string returned by the toString method of the objects. The problem is that the ListView shows only the last item repeated.
XML:
<ListView
android:id="@+id/list"
android:layout_width="363dp"
android:layout_height="409dp"
android:drawSelectorOnTop="false"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintVertical_bias="0.408" />
Java code inside the onCreate():
listView = findViewById(R.id.list);
//loadTickets();
tickets = new ArrayList<Ticket>();
tickets.add(new Ticket(1,"15.08.2017 ore 15:30","s","Comprato pane"));
tickets.add(new Ticket(2,"16.08.2017 ore 16:30","s","Spesa supermercato"));
tickets.add(new Ticket(3,"22.08.2017 ore 17:42","s","Shopping vestiti"));
tickets.add(new Ticket(4,"27.08.2017 ore 20:00","s","Libreria"));
tickets.add(new Ticket(5,"02.09.2017 ore 07:15","s","Alimentari"));
adapter = new ArrayAdapter<Ticket>(this, android.R.layout.simple_list_item_1, tickets);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
The Ticket class is a really simple class with some strings and a toString method that returns the concatenation of them.
The error was: static variables in the class that had to be shown in the list view. I removed the static attribute and everything is fixed