How to refresh list view dynamically in Android?

Android List view refresh

  • I have one ListView which is showing me some data through an array (which is in another class and I'm accessing it through it's object). Whenever I delete an element from the ListView through context menu, the list is not refreshing but the element is deleted from the array. How can I refresh the list to show this? Code: public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (v.getId()==R.id.mainListView) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; post=info.position; menu.setHeaderTitle(stocks[info.position]); String[] menuItems = stt; for (int i = 0; i<menuItems.length; i++) { menu.add(Menu.NONE, i, i, menuItems[i]); } } } @Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); int menuItemIndex = item.getItemId(); String[] menuItems = stt; String menuItemName = menuItems[menuItemIndex]; listItemName = stocks[info.position]; stockname.remove(post-1); return true; }

  • Answer:

    You have to notify your ListView adapter that the data has changed. listViewAdapater.notifyDataSetChanged(); If that for some reason doesnt work, and there are some wierd situations where it seems like it wasnt notifying, you can just reasing your adapter via the constructor with the updated array.

vivek_Android at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.