I wanted to know how to refresh a ListActivity
when I change/add data to it.
I first thought that ListAdapter
would know when the list is changes, but when I have added elements to the list there is no update on the ListActivity
, only when I close the ListActivity and reopen it again I see the changes occur.
So I searched for any method such as: update(), refesh()
or something like that, but there is none.
It seems I haven't gotten the concept, can someone help me please?
This example demonstrates how do I dynamically update a ListView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
notifyDataSetChanged. Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.
In order to display items in the list, call setAdapter(android. widget. ListAdapter) to associate an adapter with the list. For a simple example, see the discussion of filling an adapter view with text in the Layouts guide.
If you are using an ArrayAdapter
, manipulate the contents of the list through the adapter -- do not touch the underlying list. There are add()
, insert()
, and remove()
methods on ArrayAdapter
.
If you are using a CursorAdapter
, run a requery()
on the Cursor
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With