T
T
ta42014-10-22 19:27:35
Android
ta4, 2014-10-22 19:27:35

How to update item in listview in android?

I have a fragment with a listview. Each item listview contains a photo and a few recent comments on it. When I click on an item, a new activity is launched where I can leave a new comment. Let's say I left and closed the activity, i.e. returned back to fragment with listview. How can I make my last comment appear in the list?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JCDenton, 2014-10-23
@JCDenton

It depends on how you supply the data for the ListView with photos. I would do the following. Create a class - a photo data provider that remembers the date of the last changes to its data set (let's call it PhotoDataProvider). After adding a new comment, in the onPause() method of the corresponding Activity, pull the PhotoDataProvider.setLastUpdateDate(new Date()) method. In a fragment with a list of photos, also remember the date of the last changes. In the fragment's onResume() method, compare dates. If the date stored in the enemy is less than the date stored in the data provider, create a new adapter for the ListView and substitute it. There is, of course, an unplowed field for optimizations. But, in general, the algorithm is something like this.

O
Oleg Dolgih, 2014-10-23
@olegvarmy

Use startActivityForResult() , leave a comment, pack everything you need into an intent, set this intent with the setResult() method, close the activity, in the onActivityResult() of the fragment, take the intent that sent and update the item listView that was clicked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question