I have my main Activity with a fragment, witch has a Recyclerview retreaving all the data populated from the database. In this fragment I got a button witch calls another activity to insert an object into the database.
The problem is when the Activity ends and returns to the Main Activity the Recyclerview doesn't show the new item I just created. I tryed with this piece of code:
@Override
public void onResume() {
super.onResume();
adapterItem.addItem(MyApplication.getWritableDatabase().getAllItems());
listProjectsView.scrollToPosition(0);
}
The function getAllItems retrieve all the data from sqlite.
On my adapterItem from my Recyclerview I got this:
public void addItem(ArrayList<Item> listItems) {
this.listItems = listItems;
notifyItemInserted(0);
}
It works "fine". The main problem is when I switch to another application in progress in my mobile and I return to my developed app the onResume method switches on and show again my last insert, populating twice this item (and so on if I do it again).
Thanks
Aucun commentaire:
Enregistrer un commentaire