vivek_Android vivek_Android - 8 months ago 79
Android Question

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?


public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
if (v.getId() {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
String[] menuItems = stt;
for (int i = 0; i<menuItems.length; i++) {
menu.add(Menu.NONE, i, i, menuItems[i]);

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];

return true;


You have to notify your ListView adapter that the data has changed.


If that for some reason doesn't work and there are some wierd situations where it seems like it wasn't notifying, you can just reassign your adapter via the constructor with the updated array.