Android List View Refresh

How to refresh Android listview?

Call notifyDataSetChanged() on your Adapter object once you've modified the data in that adapter.

Some additional specifics on how/when to call notifyDataSetChanged() can be viewed in this Google I/O video.

Android: how to refresh ListView contents?

To those still having problems, I solved it this way:

List<Item> newItems = databaseHandler.getItems();

I first cleared the data from the adapter, then added the new collection of items, and only then set notifyDataSetChanged();
This was not clear for me at first, so I wanted to point this out. Take note that without calling notifyDataSetChanged() the view won't be updated.

How refresh ListView?

I would suggest using RecyclerView instead of ListView. Also, you can create a method in your adapter which would take the list of data and set it and use notifydatasetchanged there.

Correct way to refresh a ListView adapter in Android

I think the correct way to do it is a use


method to launch your Second activity (where your new items is added).

And in your second activity use


(diffrent result when new items is added or user just back to prev screen).

Then in your ListAdapter class add method

public void updateData(List data) { = new ArrayList<>(data);

And call it in your onActivityResults(...)

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == YOUR_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
adapter.updateData(...your data from result Intent, or from anywhere else...);

Also i strongly recommend you to use RecyclerView instead of ListView

UPD: to answer your question - i think that biggest mistake in your code, is to create new instance of ListAdapter object in onResume() method, when it's not necessary

How to refresh ListView dynamically?


You can call the above method to refresh list view any time. In your case call it after you delete a record from database.

Refresh ListView from ArrayAdapter

You are instantiating a new adapter each time. What you have to do is put the line where you instantiate the adapter before the click listener, and in the click listener modify that adapter and call notifyDataSetChanged() on it. You of course have to add some setters to your adapter in order to modify the data.

Has to look similar to this:

protected void onCreate(Bundle savedInstanceState) {
listView=(ListView) findViewById(;

//instantiate the adapter (just one time)
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, xmlFileManager.getHiddenNumbers());

//assign the adapter to the listview

xmlFileManager=new XmlFileManager(this);
addNumber=(Button) findViewById(;

addNumber.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {

LayoutInflater factory = LayoutInflater.from(HiddenCall.this);
final View alertDialogView = factory.inflate(R.layout.add_number, null);
AlertDialog.Builder adb = new AlertDialog.Builder(HiddenCall.this);

final AlertDialog alertDialog = adb.create();

adb.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
numberToAdd=(EditText) alertDialogView.findViewById(;
String number = numberToAdd.getText().toString();
xmlFileManager.addNumberToXml(number , HIDDEN_NUMBER_TYPE);
//adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, xmlFileManager.getHiddenNumbers());

//set the changed data

//notify that the model changed
} });

adb.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
} });;


How to refresh listview when click an item on listview

Your choices are:

  • Use the functions of the ArrayAdapter to modify the underlying List (add, insert, remove, clear, etc.)
  • Re-create the ArrayAdapter with the new List data. (Uses a lot of resources and garbage collection.)
  • Create your own class derived from BaseAdapter and ListAdapter that allows changing of the underlying List data structure.
  • Use the notifyDataSetChanged every time the list is update. To call it on the UI-Thread use the runOnUiThread method of the Activity. Then notifyDataSetChanged will work.


final ArrayAdapter adapter = ((ArrayAdapter)getListAdapter());
runOnUiThread(new Runnable() {

public void run() {

Related Topics

Leave a reply