-1
我使用了搜索按鈕,但我只找到自定義列表視圖的解決方案。 我在我的活動中有一個非常簡單的ListView,它應該只顯示對象的toString方法返回的字符串。 問題是ListView只顯示重複的最後一個項目。重複ListView項目
XML:對的onCreate(內
<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代碼):
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();
票證類是一個非常簡單的類的一些字符串,並返回它們的級聯進行的toString方法。
謝謝,我不知道。我刪除了,但我仍然有同樣的問題 –
可能重複的[如何使用ArrayAdapter](https://stackoverflow.com/questions/2265661/how-to-use-arrayadaptermyclass) –
nomag
添加'tickets.clear() ;'然後'ticket = new ArrayList();' –